-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathbiconnected.cpp
More file actions
55 lines (46 loc) · 1016 Bytes
/
biconnected.cpp
File metadata and controls
55 lines (46 loc) · 1016 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
54
55
namespace CBC {
vector<int> Stack;
int Depth[kMaxN], Time[kMaxN], Low[kMaxN];
vector<int> Nodes[kMaxN];
int Art[kMaxN];
int n, cbc;
void Init(int nn) {
n = nn;
for(int i = 1; i <= n; ++i) {
Time[i] = Low[i] = Art[i] = 0;
Nodes[i].clear();
}
cbc = 0;
Stack.clear();
}
void DFS(int node) {
static int timer;
Stack.push_back(node);
Low[node] = Time[node] = ++timer;
for(auto vec : G[node]) {
if(!Time[vec]) {
Depth[vec] = Depth[node] + 1;
DFS(vec);
Low[node] = min(Low[node], Low[vec]);
if(Low[vec] >= Time[node]) {
auto &To = Nodes[++cbc];
do {
To.push_back(Stack.back());
Stack.pop_back();
} while(To.back() != vec);
To.push_back(node);
}
} else if(Depth[vec] < Depth[node] - 1) {
Low[node] = min(Low[node], Time[vec]);
}
}
}
void MakeArticulationPoints() {
for(int i = 1; i <= cbc; ++i) {
for(auto node : Nodes[i])
Art[node] += 1;
}
for(int i = 1; i <= n; ++i)
Art[i] = (Art[i] >= 2);
}
};