forked from bamsarts/DS-ALGO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArtPoint and Bridge.cpp
41 lines (36 loc) · 1.06 KB
/
ArtPoint and Bridge.cpp
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
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
int ind[MAXN], inst[MAXN], ll[MAXN];
int cnt = 1;
stack <int> s;
vector<int> g[MAXN], AP, B;
void tarjan (int node, int par){
ind[node] = ll[node] = cnt++;
s.push(node);
int child = 0;
for(auto x : g[node]){
if (!ind[x]) {
child++;
tarjan(x, node);
ll[node] = min(ll[node], ll[x]);
if ((ll[x] >= ind[node] && par != 0) || (par == 0 && child > 1)){
// x can't reach node ( no backward edge from x to node )
// and x can't reach any anc. of node
// cutting node splits children of x and anc. of node
// par != 0 to prevent case 1 -> 2 -> 3
// par == 0 && child > 1 to prevent case 1 -> 2, 1-> 3
AP.push_back(node);
}
if (ll[x] > ind[node]) {
B.push_back(node);
}
}
else if (inst[x]) {
ll[node] = min(ll[node], ind[x]);
}
}
}
int main(){
return 0;
}