标签:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm>
#include<stdlib.h>
#define LL __int64
using namespace std;
int fa[3000];
int val[3000];
int find(int x)
{
if(x==fa[x])
return x;
int s=fa[x];
fa[x]=find(fa[x]);
val[x]+=val[s];
return fa[x];
}
void bincha(int x,int y) // x xiao y da
{
int fx=find(x);
int fy=find(y);
if(fx!=fy)
{
fa[fx]=fy;
val[fx]=val[y]+val[x]+1;
//val[x]=val[y]+1;
}
}
int main()
{
int n;
int i,j,k;
int xiao,da;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<=2000;i++)
{
fa[i]=i;
}
memset(val,0,sizeof(val));
for(i=0;i<n;i++)
{
scanf("%d%d",&xiao,&da);
bincha(xiao,da);
}
find(1);
find(2);
if(val[1]<val[2])
{
printf("You are my younger\n");
}
else if(val[1]>val[2])
{
printf("You are my elder\n");
}
else
{
printf("You are my brother\n");
}
}
return 0;
}
NBUT 1218 You are my brother(带权并查集)
标签:
原文地址:http://www.cnblogs.com/sola1994/p/4738016.html