#include<stdio.h>
#include<string.h>
int d[200][200],mark[201],du[201];
int main()
{
int n,i,j,k,m;
while(scanf("%d%d",&n,&m),n)
{
memset(du,0,sizeof(du));
memset(d,0,sizeof(d));
memset(mark,0,sizeof(mark));
for(i=1; i<=m; i++)
{
scanf("%d%d",&j,&k);
if(d[j][k]==0)
{
d[j][k]=1;
du[k]++;
}
}
int f;
for(i=0; i<n; i++)
{
f=0;
for(j=0; j<n; j++)
{
if(du[j]==0&&mark[j]==0)
{
mark[j]=1;
for(int x=0; x<n; x++)
{
if(d[j][x]!=0)
du[x]--;
}
f=1;
break;
}
}
if(f==0)
break;
}
if(f==0)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
拓扑排序B
最新推荐文章于 2021-05-18 03:38:16 发布