当前位置:网站首页>Cut point of undirected graph
Cut point of undirected graph
2022-07-03 01:07:00 【chengqiuming】
One Cut point decision rule
If x Not the root node , be x It's a cut , If and only if it exists on the search tree x A child node of y, Satisfy low[y]>=dfn[x], if x It's a cut , If and only if there are at least two child nodes in the search tree , Satisfy low[y]>=dfn[x].
in other words , If not root , And children's low The value is greater than or equal to your dfn value , Then this node is the cut point ; If it's a root , Then at least two children need to meet the conditions . In the following illustration ,5 The children of are 7, Satisfy low[7] > low[5], therefore 5 It's a cut .

Two Cut point determination
1 Not a cut point

1 Not a cut point :1 It's a root , Only one child is satisfied low{2}>dfn[1]
2 When the cutting point is the root

1 It's a cut :1 It's a root , Two children are satisfied low{2}>dfn[1],low[3]>dfn[1]
3 The cutting point is not the root

2 and 3 It's a cut :low[3]>dfn[2],low[4]=dfn[3]
3、 ... and Code
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) { // Add an edge u--v
e[++cnt].next = head[u];
e[cnt].to = v;
head[u] = cnt;
}
static void tarjan(int u, int fa) { // Please cut point
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 + " It's a cut ");
}
}
} 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;
}Four test
Green is the input , White is the output .

边栏推荐
- JS inheritance and prototype chain
- MongoDB系列之MongoDB常用命令
- How to convert Quanzhi a40i/t3 to can through SPI
- Inversion de l'intervalle spécifié dans la liste des liens
- 删除有序链表中重复的元素-II
- leetcode:701. 二叉搜索树中的插入操作【bst的插入】
- 1.12 - Instructions
- 2022 list of manufacturers of Chinese 3D vision enterprises (guided positioning and sorting scenes)
- leetcode-871:最低加油次数
- Solve the cache problem of reactnative using WebView
猜你喜欢

【AutoSAR 三 RTE概述】

全志A40i/T3如何通过SPI转CAN

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

无向图的割点

测试右移:线上质量监控 ELK 实战

Initial order of pointer (basic)

指针进阶(一)

Test shift right: Elk practice of online quality monitoring
![[shutter] image component (configure local GIF image resources | load placeholder with local resources)](/img/73/19e2e0fc5ea6f05e34584ba40a452d.jpg)
[shutter] image component (configure local GIF image resources | load placeholder with local resources)
![[C language] branch and loop statements (Part 1)](/img/47/6efcc59bd26e26f66c698635c26c8b.png)
[C language] branch and loop statements (Part 1)
随机推荐
关于Fibonacci数列
[applet project development -- JD mall] user defined search component of uni app (middle) -- search suggestions
【AutoSAR 九 C/S原理架构】
Embrace the safety concept of platform delivery
解决ReactNative使用webView存在缓存问题
Vulkan practice first bullet
【C语言】分支和循环语句(上)
leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
Arduino开发之按键检测与正弦信号输出
Leetcode-2280: represents the minimum number of line segments of a line graph
R language ggplot2 visualization: use ggplot2 to display dataframe data that are all classified variables in the form of thermal diagram, and customize the legend color legend of factor
基于ARM RK3568的红外热成像体温检测系统
lex && yacc && bison && flex 配置的問題
How to convert Quanzhi a40i/t3 to can through SPI
Basic use of sringcloud & use of component Nacos
Initial order of pointer (basic)
无向图的割点
excel去除小数点后面的数据,将数字取整
1038 Recover the Smallest Number
瑞萨电子RZ/G2L开发板上手评测