-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbiconnected.cpp
More file actions
51 lines (46 loc) · 1022 Bytes
/
biconnected.cpp
File metadata and controls
51 lines (46 loc) · 1022 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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <stack>
using namespace std;
vector<int> low, pre, artpts, bccno;
vector< vector<int> > g;
stack< pair<int,int> > S;
int cnt = 1, bcc_cnt;
void dfs(int u, int p)
{
low[u] = pre[u] = cnt;
++cnt;
int ch = 0;
for(int i = 0; i < g[u].size(); ++i) {
int v = g[u][i];
if (pre[v] == 0) {
S.push(make_pair(u, v));
++ch;
dfs(v, u);
low[u] = min(low[u], low[v]);
if (low[v] >= low[u]) {
artpts[u] = 1;
++bcc_cnt;
while (!S.empty()) {
pair<int,int> e = S.top(); S.pop();
bccno[e.second] = bcc_cnt;
bccno[e.first] = bcc_cnt;
if (e.first == u && e.second == v) break;
}
}
} else if (pre[v] < pre[u] && v != p) {
S.push(make_pair(u, v));
low[u] = min(low[u], pre[v]);
}
}
if (p < 0 && ch == 1) artpts[u] = 0;
}
int main()
{
return 0;
}