Result: Accepted
Time: 187ms
Memory: 5540kB
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
using namespace std;
const int maxn=200010;
const int TNF=0x3f3f3f;
int n,m;
int f[maxn];
map<int,int>mp;
void init(){
for(int i=1;i<=n;i++){
f[i]=i;
}
}
int findf(int x){
return f[x]==x?f[x]:f[x]=findf(f[x]);
}
int merge(int x,int y){
if(findf(x)!=findf(y)) f[findf(y)]=findf(x);
}
int main(){
int a,b;
while(scanf("%d %d",&n,&m)!=EOF){
init();
for(int i=1;i<=m;i++){
scanf("%d %d",&a,&b);
merge(a,b);
}
int cnt=0;
int max=0;
for(int i=1;i<=n;i++){
mp[findf(i)]++;
if(mp[findf(i)]>max) max=mp[findf(i)];
}
printf("%d\n",max);
mp.clear();
}
}