标签:
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others)
Total Submission(s): 18767 Accepted Submission(s): 6896
1 #include<cstdio> 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 #define N 100010 7 int F[N]; 8 int G[N]; 9 int Gf(int t) 10 { 11 if(F[t]==-1) return t; 12 F[t] = Gf(F[t]); 13 return F[t]; 14 } 15 int mx; 16 void bing (int a , int b) 17 { 18 int fa = Gf(a); 19 int fb = Gf(b); 20 if(fa!=fb) 21 { 22 F[fa] = fb; 23 G[fb] += G[fa]; 24 mx = max(mx,G[fb]); 25 } 26 } 27 int main() 28 { 29 int n; 30 while(~scanf("%d",&n)) 31 { 32 mx = 0; 33 memset(F,-1,sizeof(F)); 34 for(int i = 1 ;i <= N ;i++) 35 { 36 G[i] = 1; 37 } 38 for(int i = 0 ;i < n ;i++) 39 { 40 int a , b; 41 scanf("%d%d",&a,&b); 42 bing (a, b); 43 } 44 printf("%d\n",mx); 45 } 46 return 0; 47 }
标签:
原文地址:http://www.cnblogs.com/shanyr/p/4689824.html