#include<stdio.h> #include<string.h> int degree[101],vis[101],map[101][101]; int main() { int n,m,a,b,i,j,temp,flag; while(~scanf("%d%d",&n,&m) && n) { memset(degree,0,sizeof(degree)); memset(vis,0,sizeof(vis)); memset(map,0,sizeof(map)); flag = 0; while(m--) { scanf("%d%d",&a,&b); if(!map[a][b]) //不计重边; { degree[b]++; map[a][b] = 1; } } for(i = 0;i < n;i ++) { for(j = 0;j < n;j ++) //查找入度为0的点; { if(degree[j] == 0 && vis[j] == 0) temp = j; } vis[temp] = 1; //找到即把此点销毁; for(j = 0;j < n;j ++) { if(j != temp && map[temp][j] == 1 && vis[j] == 0) //处理与此点相关的点和边; { degree[j]--; map[temp][j] = 0; //销毁边; } } } for(i = 0;i < n;i ++) //验证是否还有入度不为0的点; { if(degree[i]) { flag = 1; break ; } } if(!flag) printf("YES\n"); else printf("NO\n"); } return 0; }