标签:des blog http java strong os
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): 13672 Accepted Submission(s): 5008
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> using namespace std; #define Maxint 10000000 int user[Maxint],rank[Maxint]; void Markset(int size) { for(int i=1;i<=Maxint;i++) { user[i]=i; rank[i]=1; } } int find(int x) { if(x!=user[x]) { user[x]=find(user[x]); } return user[x]; } void Union(int x,int y) { x=find(x); y=find(y); if(x == y)return ; if(x!=y) { user[x]=y; rank[y]+=rank[x]; } } int main() { int n,m,i,j,a,b; while(scanf("%d",&n)!=EOF) { if(n ==0){printf("1\n"); continue;} Markset(n); int max=0; for(i=0;i<n;i++) { scanf("%d%d",&a,&b); if(a>max) max=a; if(b>max) max=b; Union(a,b); } int Max=0; for(i=1;i<=max;i++) { if(rank[i]>Max) Max=rank[i]; } printf("%d\n",Max); } return 0; }
标签:des blog http java strong os
原文地址:http://www.cnblogs.com/ccccnzb/p/3834146.html