标签:
Description
Input
Output
Sample Input
Sample Output
#include <iostream> #include<cstdio> #include<cstring> using namespace std; int f[100005],vis[100005]; int x,y,flag; int getfather(int x) { if (f[x]!=x) { f[x]=getfather(f[x]); return f[x]; } else return x; } int main() { while(scanf("%d%d",&x,&y),x!=-1) { for(int i=1;i<=100000;i++) f[i]=i; memset(vis,0,sizeof(vis)); flag=1; while (x!=0) { int fx=getfather(x); int fy=getfather(y); vis[x]=1; vis[y]=1; if (fx==fy) flag=0; else f[fy]=fx; scanf("%d%d",&x,&y); } int k=0; for(int i=1;i<=100000;i++) if (f[i]==i && vis[i]) { k++; if (k>=2) {flag=0; break;} } if(flag) printf("Yes\n"); else printf("No\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/stepping/p/5465520.html