重連通分量的求解

2022-05-15 02:19:23 字數 1380 閱讀 4729

提兩點:

1.對於每個點連通分量,都是根據割點來找的。

2.邊入棧, 到當前邊等於棧頂時停止出棧。

3.割點屬於多個點連通分量。

鄰接矩陣:

view code

#include#include

#define maxn 22

#define maxm 444

#define inf 1000000000

int min(int a, intb)

intn, m;

bool

map[maxn][maxn];

struct

ee

bool cmp(ee &t)

}e[maxm];

inttop;

intdfn[maxn];

intlow[maxn];

intid;

void dfs(int

u) printf("\n

");}

}else low[u] =min(low[u], dfn[v]);}}

}void

init()

intmain()

dfs(1);

}return0;

}/*7 9

1 21 3

1 61 7

2 32 4

2 54 5

6 7*/

鄰接表:

view code

#include#include

#define maxn 22

#define maxm 444

#define inf 1000000000

int min(int a, intb)

struct

eedge[maxm];

inthead[maxn], tot;

intn, m;

void add(int s, int

t)struct

ee

bool cmp(ee &t)

}e[maxm];

inttop;

intdfn[maxn];

intlow[maxn];

intid;

void dfs(int u, int

fa) printf("\n

");}

}else low[u] =min(low[u], dfn[v]);}}

}void

init()

intmain()

dfs(

1, -1

); }

return0;

}

雙連通分量的求解

雙連通分量是圖論中的乙個重要模型,它的求解方式和割頂的差不多。裡用乙個棧來儲存雙連通分量中的點。注意,這裡所說的雙連通分量是點 雙連通分量 下面是核心 class edge bool iscut maxn vector g maxn vector bcc maxn stack s int n,m,l...

BFS 連通分量 求連通分量

題目描述 求乙個圖的連通分量 input n 頂點數 100 邊 以0 0作為結束標誌 output 連通分量 強連通圖的連通分量為其本身。如果為非連通圖,則連通分量為該圖的最大連通子圖。分析 建乙個100 100的布林矩陣,b x,y true表示x與y連通。同時還要記錄該點是否被遍歷過 然後遍歷...

點連通分量 邊連通分量 割點和橋 強連通分量

老是搞不清他們的關係,不知道該用那份 今天理了一下,整理一下模板 點連通分量 可以求出點連通分量包含哪些點,那個點屬於那個連通分量 struct edge int pre maxn iscut maxn bccno maxn dfs clock,bcc cnt vectorg maxn bcc ma...