POJ-2395-Out of Hay
来源:互联网 发布:dw软件的基本 编辑:程序博客网 时间:2024/04/29 04:19
这个题就是求最小生成树的边权最大值,水题~
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int maxn=11000;struct Node{ int from; int to; int c; bool operator < (const Node &a)const {return c<a.c; }}a[maxn];int n,m,p[maxn];int find(int x){ if(p[x]==-1)return x; return p[x]=find(p[x]);}int main(){ while(scanf("%d%d",&n,&m)!=EOF) {memset(p,-1,sizeof(p));for(int i=0;i<m;i++) scanf("%d%d%d",&a[i].from,&a[i].to,&a[i].c);sort(a,a+m);int ans=0;for(int i=0;i<m;i++){ int x=find(a[i].from); int y=find(a[i].to); if(x!=y) {p[x]=y;ans=a[i].c; }}printf("%d\n",ans); } return 0;}
0 0
- poj 2395 Out of Hay
- poj 2395 Out of Hay
- poj 2395 Out of Hay
- poj 2395 Out of Hay
- poj -2395-Out of Hay
- POJ-2395-Out of Hay
- POJ 2395 Out of Hay
- POJ 2395 Out of Hay
- POJ 2395 Out of Hay
- Out of Hay.(POJ-2395)
- POJ 2395 Out of Hay
- POJ 2395 Out of Hay
- POJ 2395--Out of Hay
- POJ-2395 Out of Hay
- POJ 2395 Out of Hay
- poj 2395 Out of Hay
- POJ 2395 Out of Hay
- poj-2395 Out of Hay
- MyEclipse连接MYSQL数据库问题
- 重新开始战斗16-编程之美-判断链表是否有环
- POJ 3233 Matrix Power Series 矩阵快速幂求A+A2+A3+…+Ak
- AppServ集成包安装后phpAdmin安全漏洞问题该如何解决?
- 如何创建无线ap
- POJ-2395-Out of Hay
- C# .net 如何抓取网页内容
- 淘宝将全面屏蔽外链二维码 伤及无辜的是卖家
- CSS3教程:box-sizing属性的理解
- 浏览器模式与文档模式的区别
- eclipse Android模拟器无法创建
- 解决了AlertDialog中的EditText无法调出输入法的问题
- bjam 初接触
- UNREFERENCED_PARAMETER的用处