voiddfs1(int u){ if(vis[u]) return; vis[u] = 1; for(int i = 0; i < g[u].size(); ++i) { dfs1(g[u][i]); } s.push_back(u); }
voiddfs2(int u){ if(sccno[u]) return; sccno[u] = cnt; for(int i = 0; i < rg[u].size(); ++i) { dfs2(rg[u][i]); } }
voidKosaraju(int n){ for(int i = 1; i <= n; ++i) { dfs1(i); } for(int i = n - 1; ~i; --i) { if(!sccno[s[i]]) { ++cnt; dfs2(s[i]); } } }
intmain(){ ios::sync_with_stdio(false); cin.tie(0); int n, m; while(cin >> n >> m) { if(n == 0 && m == 0) break; init(n); for(int i = 0; i < m; ++i) { int u, v; cin >> u >> v; g[u].push_back(v); rg[v].push_back(u); } Kosaraju(n); cout << (cnt == 1? "Yes": "No") << endl; } return0; }