标签:des style blog http color os 文件 数据
1 #include <iostream> 2 #include<stdio.h> 3 #include<cstring> 4 5 using namespace std; 6 #define MAXN 100100 7 int fa[MAXN]; 8 int sign[MAXN]; 9 int flag; 10 11 int getHead(int a) 12 { 13 while(a!=fa[a]) a=fa[a]; 14 return a; 15 } 16 17 void uni(int x,int y) 18 { 19 int fa_x=getHead(x); 20 int fa_y=getHead(y); 21 if(fa_x==fa_y) flag=0; 22 else fa[fa_x]=fa_y; 23 } 24 25 int main() 26 { 27 int A,B; 28 while(1){ 29 memset(fa,0,sizeof(fa)); 30 memset(sign,0,sizeof(sign)); 31 scanf("%d%d",&A,&B); 32 if(A==-1&&B==-1) break; 33 if(A==0&&B==0) { 34 printf("Yes\n\n"); 35 continue; 36 } 37 38 fa[A]=A,fa[B]=A; 39 sign[A]=1,sign[B]=1; 40 41 flag=1; 42 while(scanf("%d%d",&A,&B)&&A!=0&&B!=0){ 43 if(!sign[A]) sign[A]=1,fa[A]=A; 44 if(!sign[B]) sign[B]=1,fa[B]=B; 45 uni(A,B); 46 } 47 48 int k=0; 49 for(int i=1;i<MAXN;i++) 50 if(sign[i]&&fa[i]==i) k++; 51 if(k>1) flag=0; 52 if(flag==0) printf("No\n\n"); 53 else printf("Yes\n\n"); 54 } 55 56 57 return 0; 58 }
标签:des style blog http color os 文件 数据
原文地址:http://www.cnblogs.com/CSU3901130321/p/3865221.html