Result: Accepted
Time: 151ms
Memory: 5076kB
#include<stdio.h>
#include<map>
const int maxn=100000+10;
long long p[maxn];
using namespace std;
int find(int x) {
if(x!=p[x])return p[x]=find(p[x]);
else return x;
}
void join(int x,int y) {
if(find(x)!=find(y)) p[find(x)]=find(y);
}
int main() {
int n,m,res,a,b;
while(scanf("%d%d",&n,&m)!=EOF) {
map<int,int>mp;
res=0;
mp.clear();
for (int i=1; i<=n; i++) {
p[i]=i;
}
for (int i=1; i<=m; i++) {
scanf("%d%d",&a,&b);
join(a,b);
}
for (int i=1; i<=n; i++) {
mp[find(i)]++;
res=max(res,mp[find(i)]);
}
printf("%d\n",res);
}
return 0;
}