inlineintrd(){ char c = getchar(); while(!isdigit(c)) c = getchar(); return c - '0'; }
intmain(){ int n = rd(), m = rd(); for (int i = 1, u, v; i <= m; ++i) { u = rd(); v = rd(); ++indeg[v]; e[u].push_back(v)); } for (int i = 1; i <= n; ++i) if (!deg[i]) q.push(i); while (!q.empty()) { int u = q.front(); q.pop(); seq.push_back(u); for (auto v : e[u]) { —-deg[v]; if (!deg[v]) q.push(v); } } if (seq.size() < n) puts(“exist loop!”); else { puts(“no loop!”); for (auto u : seq) printf(“%d “, u); } return0; }
inlineintrd(){ char c = getchar(); while(!isdigit(c)) c = getchar(); return c - '0'; }
intmain(){ int n = rd(), m = rd(); for(int i = 1; i <= m; ++i){ int u = rd(), v = rd(); ++indeg[v]; a[u].push_back(v); } for(int i = 1; i <= n; ++i){ if(!indeg[i]){ q.push(i); seq.push_back(i); f[i] = 0; } } while(!q.empty()){ int u = q.front(); q.pop(); for(auto i : a[u]){ —-indeg[i]; f[i] = max(f[i], f[u] + 1); if(!indeg[i]){ q.push(i); seq.push_back(i); } } } if(seq.size() < n) printf(“inf”); else{ int Max = 0; for(int i = 1; i <= n; ++i) Max = max(Max, f[i]); printf(“%d”, Max); } return0; }
inlineintrd(){ char c = getchar(); while(!isdigit(c)) c = getchar(); return c - '0'; }
intmain(){ int n = rd(), m = rd(); for(int i = 1; i <= m; ++i){ int u = rd(), v = rd(); ++indeg[v]; a[u].push_back(v); } for (int i = 1; i <= n; ++i) f[i] = 1; for(int i = 1; i <= n; ++i){ if(!indeg[i]){ q.push(i); seq.push_back(i); } } while(!q.empty()){ int u = q.front(); q.pop(); for(auto i : a[u]){ —-indeg[i]; f[i] += f[u]; if(!indeg[i]){ q.push(i); seq.push_back(i); } } } if(seq.size() < n) printf(“inf”); else{ int ans = 0; for(int i = 1; i <= n; ++i) ans += f[i]; printf(“%d”, ans); } return0; }