/*代码非常乱- -!,这道题要注意使用了哪些数字作为城市的编号,
如1 3 2 3 5 5 0 0这组数据,4没有使用到,连通数为2,不符合条件*/
#include<iostream>
#include<stdio.h>
#include<string.h>
#define N 100005
using namespace std;
typedef struct
{
int rank,parent;
}UFS;
UFS t[N];
int use[N]; //记录使用过的城市编号
void MakeSet(int n)
{
int i;
for(i=1;i<=n;i++)
{
t[i].parent = i;
t[i].rank = 0;
}
}
int FindSet(int v)
{
if (t[v].parent!=v)
return FindSet(t[v].parent);
else return v;
}
int Union(int u,int v)
{
u = FindSet(u);
v = FindSet(v);
if (u==v)return 0;
if (t[u].rank>t[v].rank)
t[v].parent = u;
else
{
t[u].parent = v;
if (t[u].rank==t[v].rank)
t[v].rank++;
}
return 1;
}
int main()
{
int x,y,flag,mark,sign;
while(true)
{
memset(use,0,sizeof(use));
MakeSet(N);
flag = 0;
sign = mark = 1;
do
{
scanf("%d%d",&x,&y);
if (x==-1 && y==-1) //输入结束
{ flag = 1;break; }
if (x==0&&y==0)break; //结束标志
use[x] = use[y] = 1; //标志使用过这个数
if (x==y)continue;
if (!sign)continue; //判断出不符合要求后,不用执行下面的,但要等数据输入完
if(!Union(x,y))
{
mark = 0; //不符合要求
sign = 0;
}
}while(true);
if (flag)break; //输入结束
if (mark)//符合两个房间中只有一条道路要求
{
int i,cnt;
for (cnt=0,i=1;i<N;i++)
if (use[i] && t[i].parent==i) //计算连通数
cnt++;
if (cnt>1)
printf("No\n");
else
printf("Yes\n");
}
else printf("No\n");
}
return 0;
}