当前位置:网站首页>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 .
边栏推荐
- 【AutoSAR 九 C/S原理架构】
- Leetcode-224: basic calculator
- Explain the basic concepts and five attributes of RDD in detail
- [flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
- Embrace the safety concept of platform delivery
- Array and collection performance comparison
- (C language) data storage
- leetcode-2115:从给定原材料中找到所有可以做出的菜
- lex && yacc && bison && flex 配置的問題
- Cordova plugin device obtains the device information plug-in, which causes Huawei to fail the audit
猜你喜欢
[AUTOSAR eight OS]
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
[case sharing] let the development of education in the new era advance with "number"
Explain the basic concepts and five attributes of RDD in detail
信息熵的基础
[introduction to AUTOSAR seven tool chain]
Infrared thermography temperature detection system based on arm rk3568
异步、郵件、定時三大任務
File operation io-part2
2022.2.14 resumption
随机推荐
Leetcode-224: basic calculator
寻找标杆战友 | 百万级实时数据平台,终身免费使用
1.12 - Instructions
Vulkan performance and refinement
12_ Implementation of rolling automatic video playback effect of wechat video number of wechat applet
Specified interval inversion in the linked list
R language generalized linear model function GLM, (model fit and expression diagnostics), model adequacy evaluation method, use plot function and car package function
【C语言】分支和循环语句(上)
Tensorflow 2. Chapter 15 of X (keras) source code explanation: migration learning and fine tuning
【AutoSAR 十二 模式管理】
安全运营四要素之资产、脆弱性、威胁和事件
瑞萨RZ/G2L ARM开发板存储读写速度与网络实测
Data analysis, thinking, law breaking and professional knowledge -- analysis method (I)
全志A40i/T3如何通过SPI转CAN
研发一款国产ARM智能边缘计算网关需要什么
Embrace the safety concept of platform delivery
[case sharing] let the development of education in the new era advance with "number"
Understanding and distinguishing of some noun concepts in adjustment / filtering
Leetcode-849: maximum distance to the nearest person
Leetcode-1964: find the longest effective obstacle race route to each position