当前位置:网站首页>无向图的割点
无向图的割点
2022-07-03 00:35:00 【chengqiuming】
一 割点判定法则
如果x不是根节点,则 x 是割点,当且仅当在搜索树上存在 x 的一个子节点 y,满足 low[y]>=dfn[x],若 x 是割点,当且仅当在搜索树上至少存在两个子节点,满足 low[y]>=dfn[x]。
也就是说,如果不是根,且孩子的 low 值大于或等于自己的 dfn 值,则该节点就是割点;如果是根,则至少需要两个孩子满足条件。在下图中,5的子节点是7,满足 low[7] > low[5],因此 5 是割点。

二 割点判定情况
1 不是割点

1不是割点:1是根,只有一个孩子满足 low{2}>dfn[1]
2 割点是根的情况

1是割点:1是根,有两个孩子满足 low{2}>dfn[1],low[3]>dfn[1]
3 割点不是根的情况

2和3是割点:low[3]>dfn[2],low[4]=dfn[3]
三 代码
package graph.targancut;
import java.util.Scanner;
public class TarjanCut {
static final int maxn = 1000 + 5;
static int n;
static int m;
static int head[];
static int cnt;
static int root;
static int low[];
static int dfn[];
static int num;
static Edge e[] = new Edge[maxn << 1];
static {
for (int i = 0; i < e.length; i++) {
e[i] = new Edge();
}
}
static void add(int u, int v) { // 添加一条边u--v
e[++cnt].next = head[u];
e[cnt].to = v;
head[u] = cnt;
}
static void tarjan(int u, int fa) { //求割点
dfn[u] = low[u] = ++num;
int count = 0;
for (int i = head[u]; i != 0; i = e[i].next) {
int v = e[i].to;
if (v == fa)
continue;
if (dfn[v] == 0) {
tarjan(v, u);
low[u] = Math.min(low[u], low[v]);
if (low[v] >= dfn[u]) {
count++;
if (u != root || count > 1) {
System.out.println(u + "是割点");
}
}
} else
low[u] = Math.min(low[u], dfn[v]);
}
}
static void init() {
head = new int[maxn];
low = new int[maxn];
dfn = new int[maxn];
cnt = num = 0;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
m = scanner.nextInt();
init();
int u, v;
while (m-- > 0) {
u = scanner.nextInt();
v = scanner.nextInt();
add(u, v);
add(v, u);
}
for (int i = 1; i <= n; i++)
if (dfn[i] == 0) {
root = i;
tarjan(1, 0);
}
}
}
class Edge {
int to;
int next;
}四 测试
绿色为输入,白色为输出。

边栏推荐
- 链表中的节点每k个一组翻转
- [C language] branch and loop statements (Part 1)
- Rust ownership (very important)
- [flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
- 【AutoSAR 十二 模式管理】
- [AUTOSAR XIII NVM]
- 合并K个已排序的链表
- 465. 最优账单平衡 DFS 回溯
- 安全运营四要素之资产、脆弱性、威胁和事件
- Unity learns from spaceshooter to record the difference between fixedupdate and update in unity for the second time
猜你喜欢

RK3568开发板评测篇(二):开发环境搭建

FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟

File operation io-part2

Thank you for being together for these extraordinary two years!

leetcode-2280:表示一个折线图的最少线段数
![[applet project development -- JD mall] user defined search component of uni app (middle) -- search suggestions](/img/ea/ee1ad50a497478b9d080bb5e4bdfb5.png)
[applet project development -- JD mall] user defined search component of uni app (middle) -- search suggestions

Infrared thermography temperature detection system based on arm rk3568

12_微信小程序之微信视频号滚动自动播放视频效果实现

文件操作IO-Part2

Lu Zhe, chief scientist of Shiping information: building data and personnel centered security capabilities
随机推荐
基于ARM RK3568的红外热成像体温检测系统
leetcode-224:基本计算器
RK3568开发板评测篇(二):开发环境搭建
深度剖析数据在内存中的存储
[shutter] image component (load network pictures | load static pictures | load local pictures | path | provider plug-in)
cordova-plugin-device获取设备信息插件导致华为审核不通过
[introduction to AUTOSAR seven tool chain]
matlab将数字矩阵保存为地理空间数据出错,显示下标索引必须为正整数类型或逻辑类型,解决
【AutoSAR 三 RTE概述】
[C language] branch and loop statements (Part 1)
1.11 - 总线
Teach you JDBC hand in hand -- structure separation
图解网络:什么是虚拟路由器冗余协议 VRRP?
瑞萨电子RZ/G2L开发板上手评测
(C language) data storage
Callback event after the antv X6 node is dragged onto the canvas (stepping on a big hole record)
1038 Recover the Smallest Number
465. DFS backtracking of optimal bill balance
[AUTOSAR eight OS]
数组与集合性能比较