Result: Accepted
Time: 50ms
Memory: 2492kB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10 ;
int fa[maxn] ;
int ggg[maxn] ;
int find(int x)
{
return fa[x] == x ? fa[x] : fa[x] = find(fa[x]);
}
void unit(int x , int y)
{
int fx = find(x) , fy = find(y) ;
fa[fx] = fy ;
}
void init(int n)
{
for(int i = 1 ; i <= n ; ++ i)
fa[i] = i ;
memset(ggg,0,sizeof ggg) ;
}
int main(int argc, char const *argv[])
{
int n , m ;
while(scanf("%d %d",&n,&m)!=EOF)
{
int cnt = 0 ;
init(n) ;
while(m --)
{
int x , y ;
scanf("%d %d",&x,&y) ;
unit(x , y) ;
}
for(int i = 1 ; i <= n ; ++ i)
{
ggg[find(i)] ++ ;
}
for(int i = 1 ; i <= n ; ++ i)
{
cnt = max(ggg[i] , cnt) ;
}
printf("%d\n",cnt) ;
}
return 0;
}