当前位置:网站首页>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 .
边栏推荐
- Leetcode-849: maximum distance to the nearest person
- Foundations of data science is free to download
- 【AutoSAR 三 RTE概述】
- Understanding and distinguishing of some noun concepts in adjustment / filtering
- Arduino开发之按键检测与正弦信号输出
- [flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
- 465. DFS backtracking of optimal bill balance
- FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟
- tail -f 、tail -F、tailf的区别
- File operation io-part2
猜你喜欢
【C语言】分支和循环语句(上)
Win10 can't be installed in many ways Problems with NET3.5
Asynchronous, email and scheduled tasks
Deep analysis of data storage in memory
[C language] branch and loop statements (Part 1)
研发一款国产ARM智能边缘计算网关需要什么
RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide
瑞萨RZ/G2L ARM开发板存储读写速度与网络实测
Vulkan practice first bullet
全志A40i/T3如何通过SPI转CAN
随机推荐
[AUTOSAR eight OS]
删除有序链表中重复的元素-II
全志A40i/T3如何通过SPI转CAN
Leetcode-2280: represents the minimum number of line segments of a line graph
安全运营四要素之资产、脆弱性、威胁和事件
MySQL multi table joint deletion
[AUTOSAR I overview]
Machine learning: numpy version linear regression predicts Boston house prices
Advanced pointer (I)
Thank you for being together for these extraordinary two years!
Asynchronous, email and scheduled tasks
Delete duplicate elements in the ordered linked list -ii
Array and collection performance comparison
[overview of AUTOSAR three RTE]
Compare version number
How to convert Quanzhi a40i/t3 to can through SPI
18_ The wechat video number of wechat applet scrolls and automatically plays the video effect to achieve 2.0
Understanding and distinguishing of some noun concepts in adjustment / filtering
excel去除小数点后面的数据,将数字取整
[AUTOSAR VI description document]