连通性2 无向图的割边 (cut edge)

这是DFS系列的第二篇

割边的概念

In graph theory, a bridgeisthmuscut-edge, or cut arc is an edgeof a graph whose deletion increases its number of connected components. Equivalently, an edge is a bridge if and only if it is not contained in any cycle. A graph is said to be bridgeless or isthmus-free if it contains no bridges.

割边 (cut edge)也称作(bridge)是删除后能使图的连通分量增加的边。

下面我们只考虑无向图。

考虑一个连通的无向图G,若它含有某条割边e(u, v),那么去掉这条边后,将得到2个连通图G‘, H‘,而不可能得到2个以上连通图,因为一条边最多能将2个连通图合为一个联通图。

下面介绍求无向图所有割边的Taryan算法(Taryan‘s Bridge-Finding Algorithm

我们只考虑对无向连通图G求割边,若图G不连通那么就对G的各个连通分量求割边。

我们知道DFS一个无向图将其所有边分成两类,树边(tree edge)与回边(back edge)。显然地,割边只能是树边而绝不可能是回边。

考虑一条树边(u-->v)是割边的条件。这条件应当是在DFS树中,以v为根的子树(简称子树v)中的所有节点都没有连向u的祖先节点(包括u本身)的回边,也就是说子树v仅仅靠着边 (u,v) 和其他节点保持连通。

为了判断上述条件,我们在DFS过程中记录每个节点的dfn值与low值,树边 (u-->v)是割边的充要条件是 low[v]>dfn[u]

struct edge{
	int to, nt;
	bool flag;
}E[MAX_E<<1];
int head[MAX_V];

int dfn[MAX_V], low[MAX_V];
int ts;	//time stamp
void dfs(int u, int f){
	dfs[u]=low[u]=++ts;
	for(int i=head[i]; ~i; i=E[i].nt){
		int &v=E[i].to;
		if(!dfn[v]){	//tree edge
			dfs(v, f);
			low[u]=min(low[u], low[v]);
			if(low[v]>dfn[u]){
				e[i].flag=e[i^1].flag=true;
			}
		}
		else if(v!=f&&dfn[v]<dfn[u]){	//back edge
			low[u]=min(low[u], dfn[v]);
		}
	}
}

void solve(int N){
	memset(dfn, 0, sizeof(dfn));
	ts=0;
	for(int i=1; i<=N; i++)
		if(!dfn[i]) dfs(i, i);
}
时间: 2024-08-25 15:49:47

连通性2 无向图的割边 (cut edge)的相关文章

ZOJ 2588 Burning Bridges(无向图求割边)

ZOJ 2588 Burning Bridges 链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2588 题意:给定一个无向图连通图,(其中可能有重边),要求去掉一条边之后,使得整个图不再连通.输出这些符合条件的边的序号. 思路:这就是一个简单的无向图求割边,需要注意的是这个无向图有重边,重边一定不是割边. 代码: /*========================================= 无向图求割点

zoj2588(连通分量,求解无向图的割边)

B - Burning Bridges Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description Ferry Kingdom is a nice little country located on N islands that are connected by M bridges. All bridges are very beautiful and a

zoj2588(无向图求割边)

这道题其实就是一道很简单的割边的模板题,不过需要处理重边导师意见有点麻烦的事 #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int MAXN=20005; const int MAXM=200005; struct edge { int to,next,id,num;//这个地方需要在原有模板

【有重边与无重边的无向图的割边求法】

无向图无重边:也就每两个顶点之间最多有一条边相连[也就是根据顶点编号即可确定边][如下] 无向图有重边如:顶点1与顶点2有两条或更多的边直接相连[也就是不能根据顶点编号来确定边][如下] 首先介绍无重边的无向图的割边求法:由于无重边的无向图中可以根据顶点来确定边,所以函数中的参数 u 和 fa  都是顶点. 1 #include <stdio.h> 2 #include <string.h> 3 #include <vector> 4 using namespace s

HDU 3849 无向图的割边

By Recognizing These Guys, We Find Social Networks Useful Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total Submission(s): 2319    Accepted Submission(s): 603 Problem Description Social Network is popular these

10.4图的连通性(Connectivity)

10.4图的连通性(Connectivity) 如果存在一条路径,使得从u到v,那么顶点u和v就是连通的 如果能存在一条路径从u到u,那么这样的路径称为自环(circuit) 路径可以视作穿过点(through the vertices),也可视为遍历边(traverses the edges) 如果这条路径穿过的边都是一次的(无重复穿过同一条边),那么我们称其为简单路径 图连通 针对于无向图而言,如果任意两个顶点都能够连通,那么称这个图为连通图 定理: 无向连通图的每对顶点都存在简单路径(si

[HDOJ4738]Caocao&#39;s Bridges(双联通分量,割边,tarjan)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 给一张无向图,每一条边都有权值.找一条割边,使得删掉这条边双连通分量数量增加,求权值最小那条. 注意有重边,ACEveryDay里群巨给的意见是tarjan的时候记录当前点是从哪条边来的. 注意假如桥的权值是0的时候也得有一个人去炸…… 1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7

ZOJ 2588 Burning Bridges 求无向图桥 边双连通裸题

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1588 binshen的板子: #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #i

HDU 4738——Caocao&#39;s Bridges——————【求割边/桥的最小权值】

Caocao's Bridges Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 4738 Description Caocao was defeated by Zhuge Liang and Zhou Yu in the battle of Chibi. But he wouldn't give up. Caocao's army st