zoj_2966 Build The Electric System
来源:互联网 发布:北京知镜科技有限公司 编辑:程序博客网 时间:2024/05/01 11:09
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1965
//C++代码#include<iostream>#include<queue>using namespace std;struct Edge{int u,v,w;bool operator <(const Edge a) const{return w>a.w;}}edge;int n,s[505];priority_queue<Edge> pq;void Union(int x,int y){s[y]=x;}int Find(int x){if(s[x]<0) return x;return s[x]=Find(s[x]);}void Kruskal(){int sum=0,num=0,i;for(i=0;i<n;i++) s[i]=-1;while(!pq.empty() && num<n-1){edge=pq.top();pq.pop();if(Find(edge.u)!=Find(edge.v)){Union(Find(edge.u),Find(edge.v));sum+=edge.w;num++;}}cout<<sum<<endl;while(!pq.empty()) pq.pop();}int main(){int t,m,i;cin>>t;while(t--){cin>>n>>m;for(i=1;i<=m;i++){cin>>edge.u>>edge.v>>edge.w;pq.push(edge);}Kruskal();}return 0;}
- zoj_2966 Build The Electric System
- Build The Electric System
- zoj_2966 Build TheElectric System
- ZOJ2966-Build The Electric System
- ZOJ 2966 Build The Electric System (kruskal)
- ZOJ 2966 Build The Electric System MST
- ZOJ 1965 Build The Electric System
- ZOJ 2966 Build The Electric System
- BNU 16485 Build The Electric System
- BNU 16485 Build The Electric System
- B - Build The Electric System --- (fisrt qualifying)
- zoj 2966 Build The Electric System
- ZOJ 2966Build The Electric System
- zoj 2966 Build The Electric System ( prim || kruskal~ )
- ZOJ 2966 Build The Electric System【最小生成树】
- zoj 2966 Build The Electric System(MST)
- BNU16485:Build The Electric System(并查集)
- 【最小生成树】ZOJ 2966 Build The Electric System
- eclipse windows 窗口背景颜色 保护视力
- 魔法师的咏唱
- 标签
- 实现ssh自动登录的4种方法
- Linux下NFS的建立与配置方法
- zoj_2966 Build The Electric System
- 长安出行难:一口锅做两样饭 长安公交大吐苦水
- Unity 3D 现在开发移动应用免费了
- css文件编码问题
- Linux 下C使用XML传递消息(字符串)
- 基础认证钓鱼
- Linux Vim自动补全
- 知识签名(signature of knowledge)
- LoadRunner中Lr_save_string()函数和Itoa()函数的使用