[cpp]
#include<cstdio>
#include<string.h>
using namespace std;
int num[1000006],con[1000006];
bool vis[1000006];
int find(int x)
{
return x==num[x]?x:num[x]=find(num[x]);
}
int main()
{ int n;
while(~scanf("%d",&n))
{if(n==0)
{printf("1\n");continue;}
for(int i=0;i<=1000005;++i)
{
num[i]=i;
vis[i]=0;
con[i]=1;
}
int a,b,x,y,max=0;
while(n--)
{
scanf("%d%d",&a,&b);
vis[a]=vis[b]=1;
x=find(a),y=find(b);
if(x!=y)
{
num[x]=y;
con[y]+=con[x];
}
}
for(int i=1;i<=1000005;++i)
{
if(vis[i])
{
x=find(i);
max=con[x];
break;
}
}
for(int i=1;i<=10005;++i)
{
if(vis[i]&&find(i)!=x)
{
if(con[find(i)]>max)
max=con[find(i)];
}
}
printf("%d\n",max);
}
return 0;
}
作者:Java_beginer1