Result: Accepted
Time: 54ms
Memory: 3276kB
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string.h>
using namespace std;
int fa[200005];
int a[200005];
int find(int x)
{
if(fa[x]==x)
{
return x;
}
else
{
return fa[x]=find(fa[x]);
}
}
void merge(int x,int y)
{
int xx=find(x),yy=find(y);
if(xx!=yy)
{
fa[xx]=yy;
}
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++)
{
fa[i]=i;
}
for(int i=1;i<=m;i++)
{
int u,v;
scanf("%d%d",&u,&v);
merge(u,v);
}
int maxn=0;
for(int i=1;i<=n;i++)
{
a[find(i)]++;
}
for(int i=1;i<=n;i++)
{
maxn=max(maxn,a[i]);
}
printf("%d\n",maxn);
}
}