A
来源:互联网 发布:淘宝贷款15万骗局 编辑:程序博客网 时间:2024/06/05 02:03
点击打开链接
某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离。省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。
当N为0时,输入结束,该用例不被处理。
31 2 11 3 22 3 441 2 11 3 41 4 12 3 32 4 23 4 50
35 Huge input, scanf is recommended.
Hint
#include<iostream>#include<algorithm>using namespace std;int root[1010];struct node{int u,v,w;}a[10010];bool cmp(node x,node y){return x.w<y.w;}int find(int x){return root[x]==x?x:root[x]=find(root[x]);}int main(){int n,i;while(scanf("%d",&n),n){int k=n*(n-1)/2;for(int i=1;i<=k;i++)cin>>a[i].u>>a[i].v>>a[i].w;sort(a+1,a+k+1,cmp);int sum=0;for(i=1;i<=n;i++)root[i]=i;for(i=1;i<=k;i++){int t1=find(a[i].u);int t2=find(a[i].v);if(t1!=t2){root[t2]=t1;sum+=a[i].w;}}cout<<sum<<endl;}return 0;}
阅读全文
0 0
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- a
- A
- A*
- a
- A
- a
- tomcat中如何配置https
- Machine Learning In Action
- setCompoundDrawables不显示图片
- Git-error: dst refspec branch matches more than one
- 训练集和测试集的产生方法
- A
- 笔记6:链表(三种:头指针、头结点、头结点循环)
- 【HDU 1495】非常可乐(BFS)
- 一张图看懂开源许可协议,开源许可证GPL、BSD、MIT、Mozilla、Apache和LGPL的区别
- 变量修饰符的定义、声明和初始化
- 数据结构实验之栈七:出栈序列判定
- 2017.8.3暑假集训第四天(下午练习赛)
- SpaceNet on AWS遥感数据集下载教程
- Machine Learning In Action