-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcses_2076.cpp
More file actions
56 lines (50 loc) · 1.1 KB
/
cses_2076.cpp
File metadata and controls
56 lines (50 loc) · 1.1 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
#include <bits/extc++.h>
using namespace std;
vector<vector<int>> G;
vector<bool> visited;
vector<int> deep, low;
vector<pair<int, int>> ans;
void dfs(int u = 0, int pre = -1, int depth = 1)
{
visited[u] = true;
low[u] = deep[u] = depth;
int child = 0;
for (auto v : G[u])
{
if (v == pre)
continue;
if (!visited[v])
{
dfs(v, u, depth + 1);
low[u] = min(low[u], low[v]);
if (low[v] > deep[u])
{
ans.emplace_back(u, v);
}
}
else if (deep[v] < deep[u])
low[u] = min(low[u], deep[v]);
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
G.resize(n), visited.resize(n), deep.resize(n), low.resize(n);
while (m--)
{
int u, v;
cin >> u >> v;
u--, v--;
G[u].emplace_back(v);
G[v].emplace_back(u);
}
dfs();
sort(ans.begin(), ans.end());
cout << ans.size() << '\n';
for (auto [u, v] : ans)
cout << u + 1 << ' ' << v + 1 << '\n';
return 0;
}