割点tarjan
割点判定法则:
- 如果× 不是根节点。 当搜索树上存在 ×的一个子节点 y。 满足
, 那么 × 就是割点。 - 如果×是根节点。 当搜索树上存在至少两个子节点 满足上述条件。 那么 x就是割点。
板子
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int head[N], to[N], nxt[N], w[N];
int tot;
void add(int a, int b, int c)
{
nxt[++tot] = head[a];
head[a] = tot;
to[tot] = b;
w[tot] = c;
}
int dfn[N], low[N], tim;
int child,root;
int cut[N];//是否为割点
void tarjan(int u)
{
dfn[u] = low[u] = ++tim;
for (int i = head[u]; i; i = nxt[i])
{
int v = to[i];
if (!dfn[v])
{
tarjan(v);
low[u] = min(low[u], low[v]);
if(low[u]>=dfn[v])
{
child++;
if(u!=root||child>1)
{
cut[u]=1;
}
}
}
else if (dfn[v])//说明v为深度小于u,指向了祖先
{
low[u] = min(low[u], dfn[v]);
}
}
}
int main()
{
return 0;
}
本文来自博客园,作者:流氓兔LMT,转载请注明原文链接:https://www.cnblogs.com/-include-lmt/p/18738818
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步