-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticulation_bridge.cpp
More file actions
64 lines (49 loc) · 1.22 KB
/
articulation_bridge.cpp
File metadata and controls
64 lines (49 loc) · 1.22 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
// BOJ 11400 단절선
#include <bits/stdc++.h>
#define sz size()
#define bk back()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dfs(int cur, int prv, int &idx, vector<vector<int>> &graph, vector<int> &vst, vector<pii> &ans) {
vst[cur] = idx;
int low = idx;
idx++;
for (int nxt : graph[cur]) {
if (nxt == prv)
continue;
if (vst[nxt]) {
low = min(low, vst[nxt]);
continue;
}
int nxt_low = dfs(nxt, cur, idx, graph, vst, ans);
low = min(low, nxt_low);
if (vst[cur] < nxt_low)
ans.push_back(make_pair(min(cur, nxt), max(cur, nxt)));
}
return low;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> graph(n + 1);
while (m--) {
int x, y;
cin >> x >> y;
graph[x].push_back(y);
graph[y].push_back(x);
}
int idx = 1;
vector<int> vst(n + 1);
vector<pii> ans;
dfs(1, 0, idx, graph, vst, ans);
sort(ans.begin(), ans.end());
cout << ans.sz << '\n';
for (pii p : ans)
cout << p.fi << ' ' << p.se << '\n';
}