#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
#define N 100005
int Father[N];
int visit[N];
void Make_set(int n)
{
for(int i=0; i<=n; i++)
Father[i] = i;
}
int Find_set(int x)
{
int pre,temp,ans;
pre = x;
while(x != Father[x])
{
x = Father[x];
}
ans = x;
while(pre != Father[pre])
{
temp = Father[pre];
Father[pre] = ans;
pre = temp;
}
return ans;
}
void Union_set(int a,int b)
{
int x = Find_set(a);
int y = Find_set(b);
Father[y] = x;
}
int main()
{
int n,m,i,j,k,temp1,temp2,flag,sum;
while(cin>>temp1>>temp2)
{
memset(visit,0,sizeof(visit));
visit[temp1] = visit[temp2] = 1;
Make_set(N);
flag = 0, sum = 0;
if(temp1==-1&&temp2==-1)
break;
if(temp1==0&&temp2==0)
{
cout<<"Yes"<<endl;
continue;
}
if(Find_set(temp1)==Find_set(temp2))
flag = 1;
else
Union_set(temp1,temp2);
while(cin>>n>>m)
{
if(n==0&&m==0)
break;
visit[n] = visit[m] = 1;
if(flag)
continue;
if(Find_set(n)==Find_set(m) || n==m)
flag = 1;
else
Union_set(n,m);
//cout<<Find_set(n)<<" "<<Find_set(m)<<endl;
}
for(i=1;i<=N;i++)
if(visit[i] && i == Find_set(i))
sum++;
if(!flag&&sum==1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
hdu_1272 小希的迷宫
最新推荐文章于 2020-08-17 15:18:11 发布