5073 @bob #include<bits/stdc++.h> using namespace std; const int N=1e4+5; const int M=5e4+5; int nxt[M], head[N], to[M], st[N], top; int col, de[N], si[N]; int dfn[N], low[N], vis[N]; int cnt=0, n, m, num=0; inline void add(int x, int y) { to[++cnt] = y; nxt[cnt] = head[x]; head[x] = cnt; } void Tarjan(int u) { dfn[u] = low[u] = ++num; st[++top] = u; for(int i=head[u];i;i=nxt[i]) { int v = to[i]; if(!dfn[v]) { Tarjan(v); low[u] = min(low[v],low[u]); } else if(!vis[v]) low[u] = min(low[u],dfn[v]);////??? } if(low[u]==dfn[u])////??????????? { vis[u] = ++col; ++si[col]; while(st[top]!=u) { ++si[col]; vis[st[top]] = col; --top; } --top; } } int main() { scanf("%d%d", &n, &m); for(int i=1;i<=m;i++) { int x, y; scanf("%d%d", &x, &y); add(y,x); } for(int i=1;i<=n;i++) { if(!dfn[i]) Tarjan(i); } for(int i=1;i<=n;i++) { for(int j=head[i];j;j=nxt[j]) { if(vis[i]!=vis[to[j]]) de[vis[to[j]]]++; } } int ans=0, u=0; for(int i=1;i<=col;i++) { if(!de[i]) ans=si[i], u++; } if(u==1) printf("%d\n",ans); else printf("0\n"); return 0; } 里面的de[], si[], co[], col,什么意思 还有,Tarjan如何实现?? https://blog.csdn.net/ESTHERWXY/article/details/95110947?utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&dist_request_id=&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control