hdu 4424 Conquer a New Region (並查集)
///題意:給出一棵樹,樹的邊上都有邊權值,求從一點出發的權值和最大,權值為從一點出去路徑上邊權的最小值
# include
# include
# include
# include
using namespace std;
# define MAX 200010
struct 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; is2)
Union(fb,fa,s1);
else
Union(fa,fb,s2);
}
printf("%I64d\n",dis[find(1)]);
}
return 0;
}