1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 int map[100][100],visited[100],du[100],flag,n,m,i,j,k; 5 int main() 6 { 7 while(~scanf("%d %d",&n,&m)) 8 { 9 memset(map,0,sizeof(map)); 10 memset(visited,0,sizeof(visited)); 11 memset(du,0,sizeof(du)); 12 while(m--) 13 { 14 int a,b; 15 scanf("%d%d",&a,&b); 16 map[a][b]=1; 17 du[b]++; 18 } 19 for(i=1; i<=n; i++) 20 { 21 flag=0; 22 for(j=1; j<=n; j++) 23 { 24 if(visited[j]==0&&du[j]==0) 25 { 26 visited[j]=1; 27 for(k=1; k<=n; k++) 28 { 29 if(map[j][k]==1) 30 du[k]--; 31 } 32 flag=1; 33 break; 34 } 35 } 36 } 37 if(flag==1)printf("YES\n"); 38 else printf("NO\n"); 39 } 40 return 0; 41 }