标签:
http://acm.hdu.edu.cn/showproblem.php?pid=1856
Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 327680/102400 K (Java/Others)
Total Submission(s): 18523 Accepted Submission(s): 6814
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #define N 10000010 int f[N], num[N]; int Find(int x) { if(x != f[x]) f[x] = Find(f[x]); return f[x]; } int main() { int n, i, x, y, rx, ry, Max; while(scanf("%d", &n) != EOF) { for(i = 0 ; i <= N ; i++) { f[i] = i; num[i] = 1; } while(n--) { scanf("%d%d", &x, &y); rx = Find(x); ry = Find(y); if(rx != ry) { f[ry] = rx; num[rx] += num[ry]; } } Max = 1; for(i = 0 ; i < N ; i++) { if(f[i] == i && Max < num[i]) Max = num[i]; } printf("%d\n", Max); } return 0; }
标签:
原文地址:http://www.cnblogs.com/qq2424260747/p/4674441.html