标签:href pid clu miss com nio ref html tput
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1232
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 50725 Accepted Submission(s):
27064
17123793 | 2016-05-11 19:16:44 | Accepted | 1232 | 31MS | 1420K | 745 B | G++ |
1 # include <stdio.h> 2 # include <string.h> 3 int pre[1005],t[1005]; 4 int find(int x) 5 { 6 int r = x; 7 while (pre[r] != r) 8 r = pre[r]; 9 int i= x,j; 10 while(i != r) 11 { 12 j = pre[i]; 13 pre[i] = r; 14 i = j; 15 } 16 return r; 17 } 18 void Union(int i,int j) 19 { 20 int x = find(i); 21 int y = find(j); 22 if (x != y) 23 pre[x] = y; 24 } 25 26 int main () 27 { 28 int n,m,i; 29 while (scanf("%d",&n) != EOF&&n) 30 { 31 for (i = 1; i <= n; i ++) 32 pre[i] = i; 33 scanf("%d",&m); 34 int a,b; 35 for (i = 1; i <= m; i ++) 36 { 37 scanf("%d%d",&a,&b); 38 Union(a,b); 39 } 40 int sum = 0; 41 memset(t,0,sizeof(t)); 42 for (i = 1; i <= n; i ++) 43 t[find(i)] = 1; 44 for (i = 1; i <= n; i ++) 45 if (t[i]) 46 sum ++; 47 printf("%d\n",sum-1); 48 } 49 return 0; 50 }
标签:href pid clu miss com nio ref html tput
原文地址:http://www.cnblogs.com/yoke/p/6506479.html