hdu 4424 Conquer a New Region (并查集)
来源:互联网 发布:linux下zip版本 编辑:程序博客网 时间:2024/06/05 20:24
///题意:给出一棵树,树的边上都有边权值,求从一点出发的权值和最大,权值为从一点出去路径上边权的最小值# include <stdio.h># include <algorithm># include <iostream># include <string.h>using namespace std;# define MAX 200010struct node{ int u,v; int w;};struct node a[MAX];__int64 dis[MAX];///存以i为根结点的边权和int father[MAX],rank[MAX];///存以i为根结点的数的节点数void init()///初始化{ for(int i=0; i<=MAX; i++) { father[i]=i; rank[i]=1; dis[i]=0; }}int cmp(node a1,node a2)///边权从大到小{ return a1.w>a2.w;}int find(int x){ if(x==father[x]) return x; return father[x]=find(father[x]);}void Union(int x,int y,__int64 v){ father[x]=y; rank[y]+=rank[x]; dis[y]=v;}int main(){ int i,n; __int64 s1,s2; while(~scanf("%d",&n)) { for(i=1; i<n; i++) scanf("%d%d%d",&a[i].v,&a[i].u,&a[i].w); init(); sort(a+1,a+n,cmp);/// for(i=1; i<n; i++) { int fa=find(a[i].v); int fb=find(a[i].u); if(fa!=fb)///树中不会出现fa,fb相等的情况。。。。 { s1=dis[fa]+a[i].w*rank[fb];///在fa集合中选点 s2=dis[fb]+a[i].w*rank[fa];///在fb集合中选点 } if(s1>s2) Union(fb,fa,s1); else Union(fa,fb,s2); } printf("%I64d\n",dis[find(1)]); } return 0;}
0 0
- Hdu 4424 Conquer a New Region 并查集
- hdu 4424 Conquer a New Region (贪心+并查集)
- hdu 4424 Conquer a New Region(并查集)
- hdu 4424 Conquer a New Region 并查集
- hdu 4424 Conquer a New Region(并查集)
- hdu 4424 Conquer a New Region (并查集)
- HDU 4424 Conquer a New Region 并查集
- 【并查集】 HDU 4424 Conquer a New Region 贪心
- hdu 4424 Conquer a New Region 并查集+思维
- HDU 4424 Conquer a New Region【贪心+并查集】
- hdu 4424 Conquer a New Region 并查集
- HDU 4424Conquer a New Region(并查集)
- HDU-4424 Conquer a New Region(并查集)
- HDU 4427 Conquer a New Region(思维 并查集)
- 【并查集】 HDOJ 4424 Conquer a New Region
- hdu 4424 & zoj 3659 Conquer a New Region (并查集 + 贪心)
- hdu 4424 Conquer a New Region(并查集,4级)
- ZOJ 3659 & HDU 4424 Conquer a New Region (并查集)
- CVS和RCS的一个简单例子
- 常用博客
- 谷歌设计师的Material Design实践心得
- strcpy/strcmp/memcpy/memcmp/strstr/ 的内部实现(转载)
- 浅谈sql server索引结构
- hdu 4424 Conquer a New Region (并查集)
- ffmpeg 1.0 filter模块AVFilterPad结构的权限属性min_perms/rej_perms分析
- 2015百度移动端研发面试小记
- RequestDispatcher ----- getRequestDispatcher()与sendRedirect()的区别
- Maven和 Sonatype Nexus私服的安装、配置及使用入门
- 第七章 7.2节练习
- STL之Input & Output Iterator
- 不要羡慕别人
- 用bytecode来看try-catch-finally和return