-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharticulation_nodes_graph.cpp
More file actions
76 lines (60 loc) · 1.35 KB
/
Copy patharticulation_nodes_graph.cpp
File metadata and controls
76 lines (60 loc) · 1.35 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define fr(x,a,b) for(ll x=a;x<b;x++)
#define PB push_back
#define MP make_pair
#define mod 1000000007
#define gmax LLONG_MAX
#define gmin LLONG_MIN
#define INF 2e9
ll n,m;
ll t=0; // time
bool visited[1001];
ll parent[1001];
bool cut_vertex[1001];
vector<ll> cv;
void dfs(ll v,vector<ll> adj[],ll low_time[],ll disc_time[]){
visited[v]=true;
low_time[v]=disc_time[v]=t+1;
ll child=0;
fr(i,0,adj[v].size()){
if(visited[adj[v][i]]==false){
child++;
parent[adj[v][i]]=v;
t++;
dfs(adj[v][i],adj,low_time,disc_time);
low_time[v]=min(low_time[v],low_time[adj[v][i]]);
if(parent[v]==-1 && child>1) cut_vertex[v]=true,cv.PB(v);
if(parent[v]!=-1 && low_time[adj[v][i]]>=disc_time[v]) cut_vertex[v]=true,cv.PB(v);
}
else{
if(parent[v]!=adj[v][i]) low_time[v]=min(low_time[v],disc_time[adj[v][i]]);
}
}
}
void initialize(){
fr(i,1,n+1){
visited[i]=false;
parent[i]=-1;
cut_vertex[i]=false;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
vector<ll> adj[n+1];
ll a,b;
fr(i,0,m){
cin>>a>>b;
adj[a].PB(b);
adj[b].PB(a);
}
ll low_time[n+1],disc_time[n+1];
initialize();
dfs(1,adj,low_time,disc_time);
fr(i,0,cv.size()) cout<<cv[i]<<" ";
return 0;
}