tarjan求割點和割邊

2022-05-27 19:06:14 字數 1864 閱讀 4004

概念

割點:在乙個無向圖中,如果刪除某個頂點,這個圖就不再連通(任意兩點之間無法相互到達),那麼這個頂點就是這個圖的割點。

割邊(橋):在乙個無向圖中刪除某條邊後,圖不再連通,那麼這條邊就是這個圖的割邊(也叫作橋)

求法

\(x\)為樹根,且\(x\)有多於乙個子樹。

\(x\)不為樹根,且滿足\(x\)為\(to\)在搜尋樹中的父親,並使得\(low_\le dfn_x\).(因為刪去\(x\)後\(to\)以及\(to\)的子樹不能到達\(x\)的其他子樹以及祖先)

code:

#include #include #include using namespace std;

int read()

while (ch >= '0'&&ch <= '9')

return x*a;

}const int maxn = 1e5+10;

int n,m;

struct nodeed[maxn*2];

int head[maxn*2],tot;

void add(int u,int to)

int dfn[maxn],low[maxn],flag[maxn],cnt,child;

void tarjan(int x,int fa)

low[x] = min(low[x],dfn[to]);

} if (child >= 2&&x == fa) flag[x] = 1;

}int main()

for (int i = 1;i <= n;i++)

int tot = 0;

for (int i = 1;i <= n;i++)

printf("%d\n",tot);

for (int i = 1;i <= n;i++)

return 0;

}

一條無向邊\((x,to)\)是橋,滿足\(low_>dfn_x\).(因為\(to\)想要到達\(x\)的父親必須經過\((x,to)\)這條邊,所以刪去這條邊圖不連通)

實現時因為是無向圖,建反邊兩條邊都要標記上,邊從\(1\)開始編號,正向邊\(x\)的反向邊就是\(x\)^\(1\)

code:

#include #include #include using namespace std;

int read()

while (ch >= '0'&&ch <= '9')

return x*a;

}const int maxn = 3e6+10;

int n,m;

struct nodeed[maxn*2];

int head[maxn*2],tot = 1;

void add(int u,int to)

int dfn[maxn],low[maxn],cnt,res;

int bridge[maxn];

void tarjan(int x, int fa)

else if (i != (fa^1)) low[x] = min(low[x],dfn[to]);

}}int main()

for (int i = 1;i <= n;i++)

int res = 0;

for (int i = 2; i < tot; i+=2)

if (bridge[i]) res++;

printf("%d\n",res);

return 0;

}

tarjan求割邊割點

內容及 來自 割邊 在連通圖中,刪除了連通圖的某條邊後,圖不再連通。這樣的邊被稱為割邊,也叫做橋。割點 在連通圖中,刪除了連通圖的某個點以及與這個點相連的邊後,圖不再連通。這樣的點被稱為割點。dfs搜尋樹 用dfs對圖進行遍歷時,按照遍歷次序的不同,我們可以得到一棵dfs搜尋樹。樹邊 在搜尋樹中的藍...

tarjan求割點和橋(割邊)

tarjan求割點和橋 例題 割點 重要的地方在 中都有注釋 include define ll long long using namespace std const ll m 2e4 10,maxn 3e6 30 int dfn m low m tot int e m 1 k,p m k2 ve...

tarjan演算法求割點割邊

在上一節我們已經知道tarjan演算法可以求聯通圖,在這裡我們也運用tarjan的思想求割點與割邊,首先我們先來說說割點,那麼什麼事割點呢,先來看一張圖 a 來自網路 在 a 圖中,我們將a點以及與a點相連的邊全部去除,會發現這個聯通圖被分成了倆個聯通圖,乙個是節點f,另外乙個是餘下的所有的節點組成...