NYOJ 502筹建工程
来源:互联网 发布:mac隐藏文件没了怎么办 编辑:程序博客网 时间:2024/04/29 08:10
题目链接:here~~
#include <iostream>#include <algorithm>#include <queue>#include <cstdio>#include <string.h>using namespace std;struct ue{ int x, y, w; bool operator < (ue a)const { return w>a.w; }};priority_queue<ue> p;int f[101];int find(int x){return f[x]==x?x:f[x]=find(f[x]);}int main(){ int N, n, m, i, j; ue a, b;// freopen("in.txt", "r", stdin); cin>>N; while (N--) { while (!p.empty()) p.pop(); for (i=0;i<101;i++) f[i]=i; cin>>n>>m; for (i=0; i<n; i++) { cin>>a.x>>a.y>>a.w; if (a.x==a.y) continue; p.push(a); } if (n<m-1) {printf("No solution\n");continue;} int k=1, res=0; while (k<m) { b=p.top(); int c=find(b.x), d=find(b.y);//找到b.x的根和b.y的根 if (c!=d){res+=b.w;f[b.y]=b.x;}//如果不相等,说明两个点不属于同一个连通,所以加上这条边的权值,并让两个点相连 p.pop();//删除当前操作的边 k++;//找到m-1个边后跳出循环,m-1是最少需要的边数 } cout<<res<<endl; } return 0;}
- NYOJ 502筹建工程
- nyoj-502-筹建工程
- nyoj 502 筹建工程
- NYOJ 502 筹建工程
- nyoj 502 筹建工程 【迪杰斯特拉】
- nyoj 502 筹建工程【最小生成树】
- NYOJ 502 筹建工程 避圈法 并查集
- 南阳502 筹建工程
- 筹建工程
- NYOJ筹建工程之并查集and最小生成树prim算法
- 畅通工程 &&筹建工程【并查集】
- 前端工程筹建NodeJs+gulp+bower
- 使用eclips或STS中maven筹建web工程
- NYOJ 608 畅通工程
- NYOJ--608 --畅通工程
- nyoj 工程---229
- NYOJ 引水工程
- NYOJ 引水工程---1239
- 类分装好的连接数据库 实例化即可使用
- POCO C++库学习和分析 -- 流 (三)
- java常用jar包用途
- myeclipse 重命名项目名
- 开源框架Pushlet入门
- NYOJ 502筹建工程
- 字符串移位包含的问题
- 记录
- Oracle GoldenGate 系列:Replicat 进程遇 OCI Error ORA-14402 错误解决办法
- Python性能建议
- 交叉编译SPECCPU2006
- STL中list的使用(理论)
- pdo分装好的连接数据库的类
- linux shell批量拷贝文件