/*
http://acm.hdu.edu.cn/showproblem.php?pid=1856
求子集个数最大值
*/
#include <stdio.h>
#include <string.h>
int boy[10000010];
int fre[10000010];
int find(int x)
{
int p = boy[x];
while(p!=x)
{
x = p;
p = boy[x];
}
return p;
}
int len(int x)
{
int cnt=0;
int p = boy[x];
while(p!=x)
{
x = p;
p = boy[x];
cnt++;
}
return cnt;
}
void merge(int x, int y)
{
int px = find(x);
int py = find(y);
if(len(x) > len(y))
{
boy[py]=px;
}
else
{
boy[px]=py;
}
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int i,a,b;
memset(fre,0,sizeof(fre));
for(i=0; i<10000010; i++)
boy[i]=i;
for(i=1; i<=n; i++)
{
scanf("%d %d",&a,&b);
merge(a,b);
}
for(i=1; i<10000010; i++)
fre[find(i)]++;
int max=0;
for(i=1; i<10000010; i++)
{
if(fre[i]>max) max=fre[i];
}
printf("%d\n",max);
}
return 0;
}
HDU 1856 More is better
最新推荐文章于 2022-12-14 05:13:38 发布
