POJ 1861 Network
来源:互联网 发布:yum nothing to do 编辑:程序博客网 时间:2024/05/02 00:22
//// main.cpp// Richard//// Created by 邵金杰 on 16/7/23.// Copyright © 2016年 邵金杰. All rights reserved.//#include<iostream>#include<algorithm>#include<queue>using namespace std;const int maxn=15000+100;int pa[maxn],u[maxn],v[maxn],w[maxn],r[maxn];int cmp(const int i,const int j) {return w[i]<w[j];}int getroot(int a) {return pa[a]==a?a:pa[a]=getroot(pa[a]);}int main(){ int n,m,ans=-1,cnt=0; queue<int> q; while(!q.empty()) q.pop(); cin>>n>>m; for(int i=1;i<=n;i++) pa[i]=i; for(int i=0;i<m;i++) r[i]=i; for(int i=0;i<m;i++) cin>>u[i]>>v[i]>>w[i]; sort(r,r+m,cmp); for(int i=0;i<m;i++) { int k=r[i]; int root1,root2; root1=getroot(u[k]); root2=getroot(v[k]); if(root1==root2) continue; ans=max(ans,w[k]); pa[root2]=root1; q.push(k); cnt++; } cout<<ans<<endl; cout<<n-1<<endl; while(!q.empty()){ int k=q.front();q.pop(); cout<<u[k]<<" "<<v[k]<<endl; } return 0;}
0 0
- POJ 1861 Network
- poj 1861 Network
- POJ 1861 Network
- poj 1861 network
- poj 1861 network
- poj 1861 network
- POJ 1861 Network(Kruskal)
- poj 1861 Network MST
- POJ 1861 Network
- POJ 1861 Network
- POJ 1861 Network
- poj 1861 Network
- POJ-1861-Network
- POJ 1861 Network
- POJ 1861 Network(Kruskal)
- POJ 1861 Network
- poj 1861 Network
- POJ:1861 Network
- js作用域链
- LeetCode-203:Remove Linked List Elements
- Sticks
- C++ vector 用法(#include <vector>)
- Codeforces Round #364 (Div. 2)
- POJ 1861 Network
- 欢迎使用CSDN-markdown编辑器
- 求解一元二次方程
- HDOJ 4506 小明系列故事——师兄帮帮忙
- 【问题解决】PHP 'Internal Server Error,500 error'
- moodle平台安装及环境配置(包括安装过程详细截图)
- 怕蛇
- php中的$_REQUEST、$_GET、$_POST
- 关于HTML学习重点-绝对布局和相对布局总结