-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgraph_articulations.cpp
More file actions
43 lines (39 loc) · 1.01 KB
/
graph_articulations.cpp
File metadata and controls
43 lines (39 loc) · 1.01 KB
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
template<int maxn>
struct ArticulationsFinder {
void addEdge(int v, int u) {
g[u].push_back(v);
g[v].push_back(u);
}
set<int> run() {
for (int v = 0; v < maxn; ++v)
if (!tin[v])
dfs(v, -1);
return artPoints;
}
private:
void dfs(int v, int p) {
static int number = 1;
tin[v] = tout[v] = number++;
int children = 0;
for (int u : g[v]) {
if (u == p) continue; // skip parent
if (tin[u]) { // is visited
tout[v] = min(tout[v], tin[u]);
} else {
++children;
dfs(u, v);
tout[v] = min(tout[v], tout[u]);
if (tout[u] >= tin[v] && p != -1)
artPoints.insert(v);
}
}
if (p == -1 && children > 1)
artPoints.insert(v);
}
// input
vector<int> g[maxn];
// temporary
int tin[maxn], tout[maxn];
// output
set<int> artPoints;
};