Result: Accepted
Time: 61ms
Memory: 3280kB
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdlib>
#include<vector>
#include<map>
#include<stack>
#include<set>
using namespace std;
const int maxn=1e5+100;
int pre[maxn];
int plane[maxn];
int sum[maxn];
int high[maxn];
int find(int x){
if(x==pre[x])
return pre[x];
else
return find(pre[x]);
}
void join(int x,int y){
int fx,fy;
fx=find(x);
fy=find(y);
if(fx!=fy){
if(high[fx]>high[fy]){
pre[fy]=fx;
high[fx]=max(high[fx],high[fy]+1);
}else{
pre[fx]=fy;
high[fy]=max(high[fy],high[fx]+1);
}
}
}
int main(){
int n,m;
while(~scanf("%d %d",&n,&m)){
memset(sum,0,sizeof(sum));
memset(pre,0,sizeof(pre));
memset(high,1,sizeof(high));
for(int i=1;i<=n;i++){
pre[i]=i;
}
for(int i=1;i<=m;i++){
int u,v;
scanf("%d %d",&u,&v);
join(pre[u],pre[v]);
}
for(int i=1;i<=n;i++){
sum[find(pre[i])]++;
}
sort(sum+1,sum+1+n);
printf("%d\n",sum[n]);
}
return 0;
}