当前位置:网站首页>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 .

边栏推荐
- 1.11 - bus
- Every k nodes in the linked list are flipped
- 【AutoSAR 一 概述】
- File operation io-part2
- How to systematically learn machine learning
- Leetcode-2280: represents the minimum number of line segments of a line graph
- The R language uses the ctree function in the party package to build conditional inference decision trees, uses the plot function to visualize the trained conditional inference decision tree, and the
- ROS2之ESP32简单速度消息测试(极限频率)
- [AUTOSAR + IO Architecture]
- Arduino开发之按键检测与正弦信号输出
猜你喜欢

电话网络问题

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

matlab 多普勒效应产生振动信号和处理

【AutoSAR 二 AppL概述】

ROS2之ESP32简单速度消息测试(极限频率)

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

【AutoSAR 一 概述】

Vulkan performance and refinement

指针进阶(一)

Infrared thermography temperature detection system based on arm rk3568
随机推荐
指针初阶(基础)
[AUTOSAR five methodology]
1696C. Fishingprince plays with array [thinking questions + intermediate state + optimized storage]
[introduction to AUTOSAR seven tool chain]
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
MongoDB系列之MongoDB常用命令
Lex & yacc & bison & flex configuration problems
The difference between relational database and non relational database
Cordova plugin device obtains the device information plug-in, which causes Huawei to fail the audit
攻克哈希的基本概念与实现
2022 list of manufacturers of Chinese 3D vision enterprises (guided positioning and sorting scenes)
拥抱平台化交付的安全理念
Deep analysis of data storage in memory
[AUTOSAR VI description document]
【AutoSAR 一 概述】
What is needed to develop a domestic arm intelligent edge computing gateway
【AutoSAR 十 IO架构】
Merge K sorted linked lists
Solve the cache problem of reactnative using WebView
有向图的强连通分量