
拓扑排序。
/* 5154 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
using namespace std; #define MAXN 105 vector<int> vec[MAXN];
vector<int>::iterator iter;
int cnt[MAXN];
int n, m; void init() {
int i; memset(cnt, , sizeof(cnt));
for (i=; i<=n; ++i)
vec[i].clear();
} bool topSort() {
int i, j, k, tmp;
int c = ;
queue<int> Q; for (i=; i<=n; ++i) {
if (cnt[i] == ) {
Q.push(i);
}
} while (!Q.empty()) {
++c;
i = Q.front();
Q.pop();
for (iter=vec[i].begin(); iter!=vec[i].end(); ++iter) {
if (--cnt[*iter] == ) {
Q.push(*iter);
}
}
} if (c < n)
return false;
else
return true;
} int main() {
int i, j, k;
bool flag; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (scanf("%d %d", &n, &m) != EOF) {
init();
for (i=; i<m; ++i) {
scanf("%d %d", &j, &k);
vec[j].push_back(k);
++cnt[k];
}
flag = topSort();
if (flag)
printf("YES\n");
else
printf("NO\n");
} return ;
}