POJ 2377 最大生成树
来源:互联网 发布:淘宝怎么判定定制产品 编辑:程序博客网 时间:2024/05/22 17:06
思路:
裸的最大生成树 不解释
//By SiriusRen#include <cstdio>#include <algorithm>using namespace std;int n,m,ans=0,cnt=0,f[100050];struct Node{int x,y,w;}node[20050];int find(int x){return x==f[x]?x:f[x]=find(f[x]);}bool cmp(Node a,Node b){return a.w>b.w;}int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++)f[i]=i; for(int i=1;i<=m;i++) scanf("%d%d%d",&node[i].x,&node[i].y,&node[i].w); sort(node+1,node+1+m,cmp); for(int i=1;i<=m;i++){ int fx=find(node[i].x),fy=find(node[i].y); if(fx!=fy)f[fx]=fy,cnt++,ans+=node[i].w; } if(cnt==n-1)printf("%d\n",ans); else puts("-1");}
0 0
- 【最大生成树】POJ 2377
- POJ 2377 最大生成树
- poj 2377 最大生成树
- POJ 2377 最大生成树
- POJ 2377(最大生成树)
- POJ 2377 最大生成树 prim实现
- POJ 2377 Bad Cowtractors 最大生成树
- POJ 2377 Bad Cowtractors(最大生成树)
- POJ 2377 Bad Cowtractors【最大生成树】
- poj 2377最大生成树 Kruskal
- POJ 2377 Bad Cowtractors 【最大生成树】
- POJ 2377 (最大生成树 Kruskal)
- POJ 2377 - Bad Cowtractors(最大生成树)
- POJ-2377--Bad Cowtractors---最大生成树
- poj 2377 最大生成树 最小生成树的变形
- poj 3723 最大生成树
- poj 2377 Bad Cowtractors(最大生成树)
- POJ - 2377 Bad Cowtractors (最大生成树,Kruskal)
- 217. Contains Duplicate *
- 机房合作之外观模式浅谈
- thrift介绍及应用(二)—简单应用
- Android AIDL的使用
- 月溅星河长路漫漫,风烟残尽独影阑珊——又是一年
- POJ 2377 最大生成树
- Mysql----Join用法(Inner join,Left join,Right join, Cross join, Union模拟Full join)及---性能优化
- Codeforces 429B B. Working out (DP)
- java类的加载 初始化时机,已经静态代码块的执行时机
- CSS 回顾
- java Servlet 接收POST数据格式
- VB 获取 Internet Explorer_Server 里面的内容
- html, xhtml, dhtml, shtml, jhtml简介
- CocoaPods