-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcutvertices.cpp
More file actions
52 lines (44 loc) · 794 Bytes
/
Copy pathcutvertices.cpp
File metadata and controls
52 lines (44 loc) · 794 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
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N = 100000;
vector<int> g[N];
int n;
int low[N], val[N], timer = 0;
void dfs(int x, int p){
val[x] = timer;
low[x] = timer;
timer++;
int numchil = 0;
bool iscutpt = false;
for(int u : g[x]){
if(u == p) continue;
if(val[u] == -1){
numchil++;
dfs(u, x);
if(p != -1 && low[u] > val[x]){
iscutpt = true;
}
low[x] = min(low[x], low[u]);
} else {
low[x] = min(low[x], low[u]);
}
}
if(p == -1 && numchil > 1) iscutpt = true;
if(iscutpt){
cout << x << " is a cutpoint\n";
}
}
int main(){
fill(val, val + N, -1); //NEED THIS!!
n = 7;
g[0] = {1};
g[1] = {0,2,3};
g[2] = {1};
g[3] = {1, 4, 6};
g[4] = {3, 5};
g[5] = {4, 6};
g[6] = {3, 5};
dfs(0, -1);
return 0;
}