[cpp] //並差集求最大秩 //一堆學生間接或直接互為朋友則合並 //人數最多的集和的人數即為最大秩 [cpp] //不知道為什麼G++超時但是C++過了 #include <iostream> using namespace std; int Father[10000001]; int Rank[10000001]; int T; int Max; void Make_Set(int x) { Father[x] = x; Rank[x] = 1; } int Find(int x) { while(x != Father[x]) { x = Father[x]; } return x; } void Union(int x,int y) { x = Find(x); y = Find(y); if(x == y) return; if(Rank[x] > Rank[y]) { Father[y] = x; Rank[x] += Rank[y]; if(Max < Rank[x]) Max = Rank[x]; } else { Father[x] = y; Rank[y] += Rank[x]; if(Max < Rank[y]) Max = Rank[y]; } } int main() { while(cin>>T) { int x,y; Max = 1; for(long i = 0; i <= 10000000; i++) { Make_Set(i); } for(int i = 1; i <= T; i++) { cin>>x>>y; Union(x,y); } cout<<Max<<endl; } return 0; }