当前位置:网站首页>无向图的割点
无向图的割点
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;
}四 测试
绿色为输入,白色为输出。

边栏推荐
- 【AutoSAR 十一 通信相关机制】
- 全志A40i/T3如何通过SPI转CAN
- In the first half of 2022, there are 10 worth seeing, and each sentence can bring you strength!
- 18_微信小程序之微信视频号滚动自动播放视频效果实现2.0
- Problèmes de configuration lex & yacc & Bison & Flex
- leetcode-2115:从给定原材料中找到所有可以做出的菜
- Is there a free text to speech tool to help recommend?
- [daily training] 871 Minimum refueling times
- Arduino开发之按键检测与正弦信号输出
- Linear programming of mathematical modeling (including Matlab code)
猜你喜欢

RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide
![[AUTOSAR eight OS]](/img/ac/fbc84c077ff9c94c840e1871171d19.png)
[AUTOSAR eight OS]

Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径

(C language) data storage

数据分析思维分析犯法和业务知识——分析方法(一)

Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)

指针初阶(基础)

The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022

2022中国3D视觉企业(引导定位、分拣场景)厂商名单

全志A40i/T3如何通过SPI转CAN
随机推荐
【日常训练】871. 最低加油次数
2022 list of manufacturers of Chinese 3D vision enterprises (guided positioning and sorting scenes)
Thread start and priority
Array and collection performance comparison
Linear programming of mathematical modeling (including Matlab code)
【AutoSAR 二 AppL概述】
1.12 - Instructions
飞凌搭载TI AM62x的ARM核心板/开发板首发上市,亮相Embedded World 2022
指针进阶(一)
18_微信小程序之微信视频号滚动自动播放视频效果实现2.0
【AutoSAR 九 C/S原理架构】
In the first half of 2022, there are 10 worth seeing, and each sentence can bring you strength!
Leetcode-2280: represents the minimum number of line segments of a line graph
Leetcode-849: maximum distance to the nearest person
How to find out the currently running version of Solr- How do I find out version of currently running Solr?
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
Test shift right: Elk practice of online quality monitoring
Rk3568 development board evaluation (II): development environment construction
Problèmes de configuration lex & yacc & Bison & Flex
Sentry developer contribution Guide - configure pycharm