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

边栏推荐
- Several cases of recursive processing organization
- leetcode:871. Minimum refueling times [Pat has done before + maximum stacking + greed]
- Meaning of Tencent cloud free SSL certificate extension file
- 【AutoSAR 二 AppL概述】
- 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
- 2022 list of manufacturers of Chinese 3D vision enterprises (guided positioning and sorting scenes)
- leetcode-871:最低加油次数
- Vulkan is not a "panacea"“
- 链表中的节点每k个一组翻转
- Array and collection performance comparison
猜你喜欢

The difference between tail -f, tail -f and tail

信息熵的基础

matlab将数字矩阵保存为地理空间数据出错,显示下标索引必须为正整数类型或逻辑类型,解决
![[AUTOSAR + IO Architecture]](/img/cf/9ea42b50bed298c0546764b63bd957.png)
[AUTOSAR + IO Architecture]

FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟

【案例分享】让新时代教育发展与“数”俱进

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

JS inheritance and prototype chain

Vulkan performance and refinement

Trois tâches principales: asynchrone, courrier et timing
随机推荐
[AUTOSAR 11 communication related mechanism]
leetcode-2280:表示一个折线图的最少线段数
数学建模之线性规划(含MATLAB代码)
leetcode-849:到最近的人的最大距离
【AutoSAR 十 IO架构】
机器学习术语
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
[overview of AUTOSAR four BSW]
【AutoSAR 九 C/S原理架构】
File operation io-part2
leetcode:701. Insertion in binary search tree [BST insertion]
The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
RISA rz/g2l processor introduction | frame diagram | power consumption | schematic diagram and hardware design guide
1.12 - Instructions
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
指针初阶(基础)
Matlab saves the digital matrix as geospatial data, and the display subscript index must be of positive integer type or logical type. Solve the problem
[AUTOSAR I overview]
Infrared thermography temperature detection system based on arm rk3568
Illustrated network: what is virtual router redundancy protocol VRRP?