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

边栏推荐
- How to systematically learn machine learning
- 百度智能云牵头打造智能云综合标准化平台
- Infrared thermography temperature detection system based on arm rk3568
- 【C语言】分支和循环语句(上)
- Illustrated network: what is virtual router redundancy protocol VRRP?
- 数学建模之线性规划(含MATLAB代码)
- Explain the basic concepts and five attributes of RDD in detail
- Leetcode-2280: represents the minimum number of line segments of a line graph
- 利亚德:Micro LED 产品消费端首先针对 100 英寸以上电视,现阶段进入更小尺寸还有难度
- Cordova plugin device obtains the device information plug-in, which causes Huawei to fail the audit
猜你喜欢

Lu Zhe, chief scientist of Shiping information: building data and personnel centered security capabilities

研发一款国产ARM智能边缘计算网关需要什么

How to convert Quanzhi a40i/t3 to can through SPI

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

Win10 can't be installed in many ways Problems with NET3.5
![[case sharing] let the development of education in the new era advance with](/img/11/af88d16dc66f00840cbfc5ba5d68bd.jpg)
[case sharing] let the development of education in the new era advance with "number"

图解网络:什么是虚拟路由器冗余协议 VRRP?

深度剖析数据在内存中的存储

RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide

Test shift right: Elk practice of online quality monitoring
随机推荐
465. DFS backtracking of optimal bill balance
【AutoSAR 十二 模式管理】
1.12 - 指令
【AutoSAR 十一 通信相关机制】
[AUTOSAR VI description document]
数学建模之线性规划(含MATLAB代码)
Win10 can't be installed in many ways Problems with NET3.5
[overview of AUTOSAR three RTE]
Key detection and sinusoidal signal output developed by Arduino
Vulkan practice first bullet
Leetcode-871: minimum refueling times
[case sharing] let the development of education in the new era advance with "number"
leetcode-224:基本计算器
瑞萨电子RZ/G2L开发板上手评测
2022.2.14 resumption
Advanced pointer (I)
Meaning of Tencent cloud free SSL certificate extension file
The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
File operation io-part2
研发一款国产ARM智能边缘计算网关需要什么