求同一集合数量最大的个数
#include<cstdio>
#include<iostream>
#include<map>
#define N 10000010
using namespace std;
int parent[N];
map<int,int> mp;
void chushi() {
for(int i = 0; i<=N; i++)
parent[i] = i;
}
int find(int x) {
if(parent[x] == x) return x;
else return parent[x] = find(parent[x]);
}
void merge(int x,int y) {
int t1 = find(x);
int t2 = find(y);
if(t1!=t2) {
parent[t1] = t2;
mp[t2] +=mp[t1];
}
}
int main() {
int n,i,j,a,b;
while(~scanf("%d",&n)) {
if(n==1) {
cout<<"1"<<endl;
continue;
}else if(n==0){
cout<<"1"<<endl;
continue;
}
chushi();
for(i = 0; i<n; i++) {
scanf("%d%d",&a,&b);
if(mp[a]==0) mp[a] = 1;
if(mp[b]==0) mp[b] = 1;
merge(a,b);
}
int max = 0;
map<int,int>::iterator it;
for(it = mp.begin(); it!=mp.end(); it++) {
int x = it->first;
if(parent[x] == x && it->second>max){
max = it->second;
}
}
cout<<max<<endl;
mp.clear();
}
}