Start: Feb, 21, 2019 12:00:00
2018-2019 ACM集训队冬季集训第二次考核
End: Feb, 21, 2019 17:00:00
Time elapsed:
Time remaining:

Problem_ID: D
Result: Accepted
Time: 75ms
Memory: 2888kB
Author: 2018212212276
In contest: 1261

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
#define maxn 100010
int parent[maxn],Rank[maxn],sz[maxn];
int find(int x)
{
	int x_root=x;
	while(parent[x_root]!=x_root)
		x_root=parent[x_root];
	return x_root;
}
void union_vertices(int x,int y)
{
	int x_root=find(x);
	int y_root=find(y);
	if(x_root!=y_root)
	{
		if(Rank[x_root]>Rank[y_root])
			parent[y_root]=x_root;
		else if(Rank[x_root]<Rank[y_root])
			parent[x_root]=y_root;
		else
		{
			parent[x_root]=y_root;
			Rank[y_root]++;
		}
	}
}
int main()
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(Rank,0,sizeof(Rank));
		memset(sz,0,sizeof(sz));
		for(int i=0;i<=n;i++)
			parent[i]=i;
		int u,v;
		for(int i=1;i<=m;i++)
		{
			scanf("%d%d",&u,&v);
			union_vertices(u,v);
		}
		for(int i=1;i<=n;i++)
		{
			if(parent[i]!=i)
				sz[find(i)]++;
		}
		sort(sz+1,sz+n+1);
		printf("%d\n",sz[n]+1);
	}
	return 0;
}