#include #define N 100 + 5 #define M 10000 + 5 int n, m, tot; int Head[N], Deg[N], q[N]; struct Edge { int next, node; }h[M]; inline void addedge(int u, int v) { h[++ tot].next = Head[u]; Head[u] = tot; h[tot].node = v; } int main() { while (scanf("%d%d", &n, &m) == 2) { tot = 0; for (int i = 1; i <= n; i ++) Deg[i] = Head[i] = 0; for (int i = 1, u, v; i <= m; i ++) { scanf("%d%d", &u, &v); addedge(u, v); Deg[v] ++; } int l = 1, r = 0; for (int i = 1; i <= n; i ++) if (!Deg[i]) q[++ r] = i; while (l <= r) { int z = q[l ++]; for (int i = Head[z]; i; i = h[i].next) { int d = h[i].node; Deg[d] --; if (!Deg[d]) q[++ r] = d; } } if (r == n) puts("YES"); else puts("NO"); } return 0; }