-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
#ifdef LOCAL | ||
#include "debug.cpp" | ||
#else | ||
#define dbg(...) 42 | ||
#endif | ||
#define endl '\n' | ||
#define fastio \ | ||
ios_base::sync_with_stdio(false); \ | ||
cin.tie(0); \ | ||
cout.tie(0); | ||
#define len(__x) (int)__x.size() | ||
using ll = long long; | ||
using ull = unsigned long long; | ||
using ld = long double; | ||
using vll = vector<ll>; | ||
using pll = pair<ll, ll>; | ||
using vll2d = vector<vll>; | ||
using vi = vector<int>; | ||
using vi2d = vector<vi>; | ||
using pii = pair<int, int>; | ||
using vii = vector<pii>; | ||
using vc = vector<char>; | ||
#define all(a) a.begin(), a.end() | ||
#define pb(___x) push_back(___x) | ||
#define mp(___a, ___b) make_pair(___a, ___b) | ||
#define eb(___x) emplace_back(___x) | ||
int lg2(ll x) { | ||
return __builtin_clzll(1) - __builtin_clzll(x); | ||
} | ||
|
||
// vector<string> dir({"LU", "U", "RU", "R", "RD", "D", | ||
// "LD", "L"}); int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0}; int | ||
// dy[] = {-1, 0, 1, 1, 1, 0, -1, -1}; | ||
vector<string> dir({"U", "R", "D", "L"}); | ||
int dx[] = {-1, 0, 1, 0}; | ||
int dy[] = {0, 1, 0, -1}; | ||
|
||
const ll oo = 1e18; | ||
int T(1); | ||
const int MAXN(1'000'000); | ||
|
||
int tin[MAXN], low[MAXN], timer, N; | ||
char vis[MAXN]; | ||
vi2d G(MAXN); | ||
vector<pii> bridges; | ||
|
||
void dfs(int u, int p = -1) { | ||
vis[u] = true; | ||
tin[u] = low[u] = timer++; | ||
|
||
for (auto v : G[u]) { | ||
if (v == p) continue; | ||
if (vis[v]) { | ||
low[u] = min(low[u], tin[v]); | ||
} else { | ||
dfs(v, u); | ||
low[u] = min(low[u], low[v]); | ||
if (low[v] > tin[u]) { | ||
bridges.emplace_back(u, v); | ||
} | ||
} | ||
} | ||
} | ||
void findBridges() { | ||
timer = 0; | ||
|
||
memset(vis, 0, sizeof(vis)); | ||
memset(tin, -1, sizeof(tin)); | ||
memset(low, -1, sizeof(low)); | ||
bridges.clear(); | ||
|
||
for (int i = 0; i < N; i++) { | ||
if (not vis[i]) dfs(i); | ||
} | ||
} | ||
|
||
int M; | ||
|
||
auto solve() { | ||
cin >> N >> M; | ||
while (M--) { | ||
int u, v; | ||
cin >> u >> v; | ||
u--, v--; | ||
G[u].emplace_back(v); | ||
G[v].emplace_back(u); | ||
} | ||
|
||
findBridges(); | ||
cout << len(bridges) << endl; | ||
for (auto &[a, b] : bridges) { | ||
cout << a + 1 << ' ' << b + 1 << endl; | ||
} | ||
} | ||
|
||
int32_t main(void) { | ||
#ifndef LOCAL | ||
fastio; | ||
#endif | ||
|
||
// cin >> T; | ||
|
||
for (int i = 1; i <= T; i++) { | ||
solve(); | ||
} | ||
} |