File tree 1 file changed +63
-0
lines changed
1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ #define ll long long
3
+ #define INF 1e18
4
+ using namespace std ;
5
+
6
+ vector<vector<ll>> adj;
7
+ vector<ll> low, discover;
8
+ vector<bool > visited;
9
+ set<ll> articulation_pts;
10
+ ll timer = 0 ;
11
+
12
+
13
+ void explore (ll u, ll p = 0 ) {
14
+ visited[u] = true ;
15
+ discover[u] = low[u] = ++timer;
16
+
17
+ ll children = 0 ;
18
+ for (ll v : adj[u]) {
19
+ if (visited[v] == false ) {
20
+ children++;
21
+ explore (v,u);
22
+ low[u] = min (low[u], low[v]);
23
+ if (p == 0 and children > 1 ) {
24
+ articulation_pts.insert (u);
25
+ }
26
+ if (p != 0 and low[v] >= discover[u]) {
27
+ articulation_pts.insert (u);
28
+ }
29
+ }
30
+ else if (v != p) {
31
+ low[u] = min (low[u], discover[v]);
32
+ }
33
+ }
34
+ }
35
+
36
+ void dfs (ll n) {
37
+ ll i;
38
+ for (i = 1 ; i <= n; i++) {
39
+ if (visited[i] == false ) {
40
+ explore (i);
41
+ }
42
+ }
43
+ }
44
+
45
+ int main () {
46
+ ll n, m, i, u, v;
47
+ cin >> n >> m;
48
+ adj.resize (n+1 );
49
+ discover.resize (n+1 );
50
+ low.resize (n+1 );
51
+ visited.assign (n+1 ,false );
52
+
53
+ for (i = 0 ; i < m; i++) {
54
+ cin >> u >> v;
55
+ adj[u].push_back (v);
56
+ adj[v].push_back (u);
57
+ }
58
+ dfs (n);
59
+ for (ll pt : articulation_pts) {
60
+ cout << pt << endl;
61
+ }
62
+ return 0 ;
63
+ }
You can’t perform that action at this time.
0 commit comments