#include<iostream>
using namespace std;
#define Size 100010
struct node
{
int e,next;
}edge1[Size],edge2[Size];
int head1[10002],head2[10003],visit[10002];
void dfs1(int i)
{
visit[i]=1;
for(int p=head1[i];p!=-1;p=edge1[p].next)
if(!visit[edge1[p].e])
dfs1(edge1[p].e);
}
void dfs2(int i)
{
visit[i]=1;
for(int p=head2[i];p!=-1;p=edge2[p].next)
if(!visit[edge2[p].e])
dfs2(edge2[p].e);
}
int main()
{
int m,n,a,b,flag=0;
int i;
while(cin>>n>>m,n||m)
{
memset(head1,-1,sizeof(head1));
memset(head2,-1,sizeof(head2));
memset(visit,0,sizeof(visit));
for(i=0;i<m;i++){
cin>>a>>b;
edge1[i].e=b;
edge1[i].next=head1[a];
head1[a]=i;
edge2[i].e=a;
edge2[i].next=head2[b];
head2[b]=i;
}
for(i=1;i<=n;i++){
if(!visit[i])
{ dfs1(i);flag++; }
}
memset(visit,0,sizeof(visit));
for(i=1;i<=n;i++){
if(flag>2)break;
if(!visit[i])
{
flag++;
dfs2(i);
}
}
if(flag==2)cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}
强联通图判断 裸强联通判断 hdu Problem-1269 迷宫城堡
最新推荐文章于 2019-11-19 21:26:57 发布