Result: Accepted
Time: 71ms
Memory: 4060kB
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>
using namespace std;
int n,m,u,v,i;
int fa[200010],xx[200010],a[200010];
int find(int x){
return x==fa[x]?x:fa[x]=find(fa[x]);
}
void bing(int x,int y){
int fx=find(x),fy=find(y);
fa[fx]=fy;
}
int main(){
while(scanf("%d %d",&n,&m)!=EOF){
int t=1;
memset(a,0,sizeof(a));
for(i=1;i<=n;i++){
fa[i]=i;
}
for(i=1;i<=m;i++){
scanf("%d %d",&u,&v);
bing(v,u);
}
for(i=1;i<=n;i++){
xx[i]=find(i);
}
/*for(i=1;i<=n;i++){
printf("%d ",xx[i]);
}*/
sort(xx+1,xx+n+1);
/*for(i=1;i<=n;i++){
printf("%d ",xx[i]);
}*/
a[1]=1;
for(i=2;i<=n;i++){
if(xx[i]!=xx[i-1]){
t++;
a[t]=1;
}
else a[t]++;
}
sort(a+1,a+t+1);
printf("%d\n",a[t]);
}
}