hdu1863-畅通工程
来源:互联网 发布:万德数据库 怎么用 编辑:程序博客网 时间:2024/06/05 23:08
畅通工程
最小生成树,通过统计连通路的个数和总路数比较,来判断是否所有的路径都已经连通了,需要注意的是这里sum应该从1 开始,因为一开始就是从某一条路出发的
// File Name: hdu1863.cpp// Author: rudolf// Created Time: 2013年04月27日 星期六 15时21分31秒#include<vector>#include<list>#include<map>#include<set>#include<deque>#include<stack>#include<bitset>#include<algorithm>#include<functional>#include<numeric>#include<utility>#include<sstream>#include<iostream>#include<iomanip>#include<cstdio>#include<cmath>#include<cstdlib>#include<cstring>#include<ctime>using namespace std;const int maxn=10005;int fa[105];struct node{int x,y,value;}edge[maxn];int find( int x ){return fa[ x ] = x == fa[ x ]? x : find( fa[ x ] );}int cmp( const node a, const node b ){return a.value < b.value;}int main(){int m,n;int i;while(cin>>n>>m){if( n == 0 )break;for( i = 1; i <= m; i++ )fa[ i ] = i;for( i = 1; i <= n; i++ ){cin>>edge[i].x>>edge[i].y>>edge[i].value;}sort( edge + 1 , edge + n + 1, cmp );int ans = 0;int sum=1;for( i = 1;i <= n; i++ ){int x1 = find( edge[ i ].x );int x2 = find( edge[ i ].y );if( x1 != x2 ){fa[ x1 ] = x2;ans += edge[ i ].value;sum++;}}if( sum == m )cout<<ans<<endl;elsecout<<"?"<<endl;}return 0;}
- 畅通工程 hdu1863
- HDU1863畅通工程
- HDU1863--畅通工程
- hdu1863-畅通工程
- hdu1863 畅通工程
- HDU1863 畅通工程
- HDU1863畅通工程
- hdu1863畅通工程
- hdu1863 畅通工程 kruskal
- hdu1863畅通工程
- HDU1863:畅通工程(kruskal)
- HDU1863 畅通工程
- HDU1863----畅通工程
- hdu1863-畅通工程
- HDU1863 畅通工程
- 【prim】HDU1863畅通工程
- hdu1863 畅通工程
- hdu1863 畅通工程
- SDRAM讲解
- VS2008 在h与cpp文件间切换快捷键
- bind delegate live的区别。在jquery中
- 求sn=a+aa+aaa+aaa......+aa...a(n个a)之值,其中a是一个数字,例如:2+22+222+2222+22222(此时n=5),n由键盘输入
- POJ 4047: Garden
- hdu1863-畅通工程
- javaSE 4.3 99乘法表
- eclipse 查看原始类出现The jar file rt.jar has no source attachment解决方法
- ubuntu 13.04 重置unity及compiz
- Application failed codesign verification。。。
- UTC 转换为Date
- 2440SDRAM讲解
- hive一些参数
- 浅谈STM32的DMA模块的使用