http://acm.hdu.edu.cn/showproblem.php?pid=1272
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#define N 100010
#define INF 0xfffffff
using namespace std; int f[N],vis[N]; int Find(int x)
{
if(x!=f[x])
f[x]=Find(f[x]);
return f[x];
} int main()
{
int a, b, pa, pb, flag, i;
while(scanf("%d%d",&a,&b),a!=-||b!=-)
{
for(i=;i<N;i++)
f[i]=i;
memset(vis,,sizeof(vis));
flag=;
if(a==&&b==)
{
printf("Yes\n");//空树也是树;
continue;
}
vis[a] = vis[b] = ;//说明此点出现过;
pa = Find(a);
pb = Find(b);
if(pa != pb)
f[pb] = pa;
else
flag = ;
while(scanf("%d%d", &a, &b), a+b)
{
vis[a] = vis[b] = ;
pa = Find(a);
pb = Find(b);
if(pa != pb)
f[pb]=pa;
else
flag=;
}
int m=;
for(i=; i<N; i++)
{
if(vis[i]== && f[i]==i)//只能有一个父节点是本身
{
m++;
if(m>)
{
flag=;break;
}
}
}
if(flag==)
printf("No\n");
else
printf("Yes\n");
}
return ;
}