拓扑排序应用,判断是否有环,,
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
const long long mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int M = 105;
int g[M][M];
int in[M];
int n,m;
int cnt;
void toposort()
{
int i,j,k;
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(in[j]==0)
{
in[j]--;
cnt++;
for(k=0; k<n; k++)
{
if(g[j][k]) in[k]--;
}
break;
}
}
}
}
int main()
{
int i,j,k;
while(cin>>n>>m)
{
if(n==0&&m==0)
break;
memset(g,0,sizeof(g));
memset(in,0,sizeof(in));
int a,b;
while(m--)
{
cin>>a>>b;
if(g[a][b]==0)
{
g[a][b]=1;
in[b]++;
}
}
cnt=0;
toposort();
if(cnt==n)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}