1
0
Fork 0
cp-templates/graph/tarjan-cut.cc

21 lines
462 B
C++
Raw Normal View History

2023-12-02 03:59:44 +00:00
void tarjan(int u, int father) {
vis[u] = true;
low[u] = dfn[u] = ++cnt;
int child = 0;
for (auto v : edge[u]) {
if (!vis[v]) {
child++;
tarjan(v, u);
low[u] = min(low[u], low[v]);
if (father != u && low[v] >= dfn[u] && !flag[u]) {
flag[u] = true;
res++;
}
} else if (v != father) low[u] = min(low[u], dfn[v]);
}
if (father == u && child >= 2 && !flag[u]) {
flag[u] = true;
res++;
}
}