-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBCC.cpp
More file actions
53 lines (52 loc) · 1023 Bytes
/
BCC.cpp
File metadata and controls
53 lines (52 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Biconnected Components (BCC)
int dfn[MAXN];
int low[MAXN];
vector<int>g[MAXN], g2[MAXN];
int b[MAXN];
int bcc;
stack<int>st;
int stamp;
void dfs(int now, int pre = 0) {
++stamp;
dfn[now] = low[now] = stamp;
st.push(now);
for (auto &i : g[now]) {
if (i == pre) continue;
if (dfn[i]) {
low[now] = min(low[now], dfn[i]);
}
else {
dfs(i, now);
low[now] = min(low[now], low[i]);
}
}
if (dfn[now] == low[now]) {
bcc++;
while (1) {
auto x = st.top();
st.pop();
b[x] = bcc;
if (x == now) {
break;
}
}
}
}
void go() {
int n, m;
cin >> n >> m;
f(m) {
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
}
dfs(1);
f1(n) {
for (auto &j : g[i]) {
if (b[j] != b[i]) {
g2[b[i]].push_back(b[j]);
}
}
}
}