forked from beet-aizu/library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharticulationpoints.cpp
67 lines (62 loc) · 1.21 KB
/
articulationpoints.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
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
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
struct ArticulationPoints{
int n,timer;
vector<vector<int> > G;
vector<int> used,pre,par,low;
set<int> ap;
ArticulationPoints(){}
ArticulationPoints(int sz):
n(sz),G(sz),used(sz),pre(sz),par(sz),low(sz){}
void add_edge(int from,int to){
G[from].push_back(to);
G[to].push_back(from);
}
void dfs(int v,int p){
pre[v]=low[v]=timer;
timer++;
used[v]=1;
for(int u:G[v]){
if(!used[u]){
par[u]=v;
dfs(u,v);
low[v]=min(low[v],low[u]);
}else if(u!=p){
low[v]=min(low[v],pre[u]);
}
}
}
void build(){
fill(used.begin(),used.end(),0);
ap.clear();
timer=1;
dfs(0,-1);
int np=0;
for(int i=1;i<n;i++){
int p=par[i];
if(p==0) np++;
else if(pre[p]<=low[i]) ap.insert(p);
}
if(np>1) ap.insert(0);
}
};
//END CUT HERE
signed main(){
int v,e;
cin>>v>>e;
ArticulationPoints ap(v);
for(int i=0;i<e;i++){
int s,t;
cin>>s>>t;
ap.add_edge(s,t);
}
ap.build();
for(int i:ap.ap) cout<<i<<endl;
return 0;
}
/*
verified on 2017/10/29
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A&lang=jp
*/