POJ 2395
来源:互联网 发布:mysql是大型数据库吗 编辑:程序博客网 时间:2024/04/30 08:53
简单题,很纯粹的最小生成树。
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;class kruskal{public: int a,b,t;}edge[10010];int n,m;int Max;int f[2010],num[2010];bool cmp(kruskal x,kruskal y){ return x.t < y.t;}int Find(int x){ if(f[x] == x) return x; else f[x] = Find(f[x]); return f[x];}int Union(int x,int y){ int a = Find(x); int b = Find(y); if(a == b) return 0; else if(num[a] >= num[b]){ f[b] = a; num[a] += num[b]; } else { f[a] = b; num[b] += num[a]; } return 1;}int main(){ // freopen("in.txt","r",stdin); cin>>n>>m; for(int i = 1;i <= n; i++){ f[i] = i; num[i] = 1; } for(int i = 1;i <= m; i++) cin>>edge[i].a>>edge[i].b>>edge[i].t; sort(edge+1,edge+m+1,cmp); Max = 0; int pos = 1; for(int i = 1;i <= m; i++){ if(Union(edge[i].a,edge[i].b) == 1){ if(edge[i].t > Max) Max = edge[i].t; pos++; } if(pos == n) break; } cout<<Max<<endl; return 0;}
0 0
- poj 2395
- POJ 2395
- poj-2395
- POJ 2395
- poj 2395
- POJ 2395
- poj 2395 Kruskal
- POJ 2395 Prim
- POJ 2395 prim
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- HDU 4821 String (字符串hash,技巧暴力)
- java中continue标记的使用
- shared_ptr线程安全性分析
- Problem D Parentheses
- Hibernate5配置异常Error executing DDL via JDBC Statement
- POJ 2395
- Codevs 1079 回家 最短路 spfa || dijkstra
- 第2.2章 WEB系统最佳实践Web.xml配置
- POJ 3278
- 【洛谷 1508】 Likecloud-吃、吃、吃
- Java——第三章(流程控制语句)项目案例
- Linux下查看SSD4K对齐EXT4分区开启Trim及验证的方法
- iOS 开发者必须知道的新特性
- 【七】最优间隔分类器问题