当前位置:网站首页>无向图的割点
无向图的割点
2022-07-03 00:35:00 【chengqiuming】
一 割点判定法则
如果x不是根节点,则 x 是割点,当且仅当在搜索树上存在 x 的一个子节点 y,满足 low[y]>=dfn[x],若 x 是割点,当且仅当在搜索树上至少存在两个子节点,满足 low[y]>=dfn[x]。
也就是说,如果不是根,且孩子的 low 值大于或等于自己的 dfn 值,则该节点就是割点;如果是根,则至少需要两个孩子满足条件。在下图中,5的子节点是7,满足 low[7] > low[5],因此 5 是割点。

二 割点判定情况
1 不是割点

1不是割点:1是根,只有一个孩子满足 low{2}>dfn[1]
2 割点是根的情况

1是割点:1是根,有两个孩子满足 low{2}>dfn[1],low[3]>dfn[1]
3 割点不是根的情况

2和3是割点:low[3]>dfn[2],low[4]=dfn[3]
三 代码
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) { // 添加一条边u--v
e[++cnt].next = head[u];
e[cnt].to = v;
head[u] = cnt;
}
static void tarjan(int u, int fa) { //求割点
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 + "是割点");
}
}
} 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;
}四 测试
绿色为输入,白色为输出。

边栏推荐
- Vulkan is not a "panacea"“
- Rust string slicing, structs, and enumeration classes
- Unity learns from spaceshooter to record the difference between fixedupdate and update in unity for the second time
- 【AutoSAR 九 C/S原理架构】
- 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
- 比较版本号
- Rk3568 development board evaluation (II): development environment construction
- Initial order of pointer (basic)
- Vulkan-性能及精细化
- 基于ARM RK3568的红外热成像体温检测系统
猜你喜欢

Deep analysis of data storage in memory

安全运营四要素之资产、脆弱性、威胁和事件

【AutoSAR 十二 模式管理】

深度剖析数据在内存中的存储

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

tail -f 、tail -F、tailf的区别
![[AUTOSAR 11 communication related mechanism]](/img/bf/834b0fad3a3e5bd9c1be04ba150f98.png)
[AUTOSAR 11 communication related mechanism]

Test shift right: Elk practice of online quality monitoring

What is needed to develop a domestic arm intelligent edge computing gateway

正确甄别API、REST API、RESTful API和Web Service之间的异同
随机推荐
[applet project development -- JD mall] user defined search component of uni app (middle) -- search suggestions
465. DFS backtracking of optimal bill balance
Rust string slicing, structs, and enumeration classes
(C language) data storage
[case sharing] let the development of education in the new era advance with "number"
KingbaseES ALTER TABLE 中 USING 子句的用法
leetcode-241:为运算表达式设计优先级
合并K个已排序的链表
详解RDD基本概念、RDD五大属性
Reading and writing speed of Reza rz/g2l arm development board storage and network measurement
Problèmes de configuration lex & yacc & Bison & Flex
[introduction to AUTOSAR seven tool chain]
Vulkan-实践第一弹
Basic use of sringcloud & use of component Nacos
数学建模之线性规划(含MATLAB代码)
leetcode-2280:表示一个折线图的最少线段数
Illustrated network: what is virtual router redundancy protocol VRRP?
这不平凡的两年,感谢我们一直在一起!
Liad: the consumer end of micro LED products is first targeted at TVs above 100 inches. At this stage, it is still difficult to enter a smaller size
Cordova plugin device obtains the device information plug-in, which causes Huawei to fail the audit