标签:交通 nbsp limit tle main accept rip break 测试
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 59364 Accepted Submission(s): 31759
1 #include<stdio.h> 2 int p[1001]; 3 int find(int x) 4 { 5 if(x!=p[x])p[x]=find(p[x]); 6 return p[x]; 7 } 8 int hebing(int x,int y) 9 { 10 p[x]=y; 11 return 1; 12 } 13 int main() 14 { 15 int a,b,c,d,i,n,x,y,sum=0; 16 while(scanf("%d",&a)!=EOF) 17 { 18 if(a==0)break; 19 scanf("%d",&b); 20 if(b==0){printf("%d\n",a-1);} 21 else{ 22 sum=0; 23 for(i=1;i<=a;i++) 24 { 25 p[i]=i; 26 } 27 for(i=0;i<b;i++) 28 { 29 scanf("%d%d",&x,&y); 30 x=find(x); 31 y=find(y); 32 hebing(x,y); 33 } 34 for(i=1;i<=a;i++) 35 { 36 if(p[i]==i)sum++; 37 } 38 printf("%d",sum-1); 39 printf("\n"); 40 } 41 } 42 return 0; 43 }
标签:交通 nbsp limit tle main accept rip break 测试
原文地址:http://www.cnblogs.com/SparkPhoneix/p/8016451.html