You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
374 B
C++

void tarjan(int u)
{
dfn[u] = low[u] = ++idx;
st[top++] = u;
for (Edge cur : G[u])
if (!dfn[cur.to])
tarjan(cur.to),
low[u] = min(low[u], low[cur.to]);
else if (!scc[cur.to])
low[u] = min(low[u], dfn[cur.to]);
if (dfn[u] == low[u] && ++cnt)
do scc[st[--top]] = cnt;
while (st[top] != u);
}