This documentation is automatically generated by competitive-verifier/competitive-verifier
#define PROBLEM \
"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_B"
#include <bits/stdc++.h>
using namespace std;
#include "graph/lowlink.hpp"
#include "templates/alias.hpp"
#include "templates/macro.hpp"
int main() {
ll N, M;
in(N, M);
VC<VC<int>> G(N);
rep(_, M) {
int a, b;
in(a, b);
G[a].emplace_back(b), G[b].emplace_back(a);
}
LowLink LG(G);
sort(all(LG.bridges));
set<pii> S;
for (auto [a, b] : LG.bridges) {
if (a > b)
swap(a, b);
S.emplace(a, b);
}
for (auto [a, b] : S)
out(a, b);
}
#line 1 "verify/aoj_grl3b.cpp"
#define PROBLEM \
"http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_B"
#include <bits/stdc++.h>
using namespace std;
#line 4 "templates/macro.hpp"
// 引数の長さで内容が変わるrep 参考: https://trap.jp/post/1224
#define overload4(a, b, c, d, ...) d
#define _rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) overload4(__VA_ARGS__, REP, _rep)(__VA_ARGS__)
#define _rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define RREP(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); i--)
#define rrep(...) overload4(__VA_ARGS__, RREP, _rrep)(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &is, std::pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 == v.size() ? "" : " ");
}
return os;
}
// pythonのprintライクな関数 参考:
// https://nyaannyaan.github.io/library/template/inout.hpp
inline void out() { std::cout << std::endl; }
template <typename T, typename... U, char sep = ' '>
void out(const T &t, const U &...u) {
std::cout << t;
if (sizeof...(u))
std::cout << sep;
out(u...);
}
// cinの短縮関数 参考: https://nyaannyaan.github.io/library/template/inout.hpp
inline void in() {}
template <typename T, class... U> void in(T &t, U &...u) {
std::cin >> t;
in(u...);
}
template <typename T> inline T ceil_div(T a, T b) { return (a + b - 1) / b; }
template <typename T> inline T mod_pow(T a, T n, T mod) {
T res = 1;
while (n) {
if (n % 2 != 0) {
res *= a;
res %= mod;
}
a *= a;
a %= mod;
n >>= 1;
}
return res;
}
template <typename T> inline T minus_mod(T a, T b) { return ((a % b) + b) % b; }
template <typename T> void apply_vec(std::vector<T> &v, T (*fn)(T)) {
for (int i = 0; i < v.size(); i++)
v[i] = fn(v[i]);
}
#line 4 "graph/lowlink.hpp"
// 参考: https://algo-logic.info/bridge-lowlink/
struct LowLink {
std::vector<int> ord, low, parents, articulation_points;
std::vector<std::vector<int>> G;
std::vector<bool> used;
std::vector<std::pair<int, int>> bridges;
LowLink(const std::vector<std::vector<int>> &_G) : G(_G) {
ord.resize(_G.size(), 0), low.resize(_G.size(), 0),
used.resize(_G.size(), false), parents.resize(_G.size(), -1);
int d = 0;
rep(i, _G.size()) {
if (!used[i])
d = dfs(i, d, -1);
}
}
int dfs(int cur, int d, int par = -1) {
used[cur] = true, ord[cur] = low[cur] = d++, parents[cur] = par;
bool is_articulation_point = false;
int child_cnt = 0;
for (const auto &nxt : G[cur]) {
if (!used[nxt]) {
child_cnt++, d = dfs(nxt, d, cur);
chmin(low[cur], low[nxt]);
if (par != -1 && ord[cur] <= low[nxt])
is_articulation_point = true;
if (ord[cur] < low[nxt])
bridges.emplace_back(cur, nxt);
} else if (nxt != par) {
chmin(low[cur], ord[nxt]);
}
}
if (par == -1 && child_cnt >= 2)
is_articulation_point = true;
if (is_articulation_point)
articulation_points.emplace_back(cur);
return d;
}
};
#line 7 "templates/alias.hpp"
template <class T> using VC = std::vector<T>;
template <class T>
using rpriority_queue = std::priority_queue<T, VC<T>, std::greater<T>>;
using ll = long long;
using ld = long double;
using pii = std::pair<ll, ll>;
using vi = VC<ll>;
using vvi = VC<vi>;
using vvvi = VC<vvi>;
using vb = VC<bool>;
using vvb = VC<vb>;
using vf = VC<double>;
using vvf = VC<vf>;
using vpii = VC<pii>;
using vvpii = VC<vpii>;
using si = std::set<ll>;
using spii = std::set<pii>;
using mii = std::map<ll, ll>;
const std::string upperlist = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const std::string lowerlist = "abcdefghijklmnopqrstuvwxyz";
#define mp make_pair
#define dms << " " <<
constexpr int MOD998 = 998244353;
#line 9 "verify/aoj_grl3b.cpp"
int main() {
ll N, M;
in(N, M);
VC<VC<int>> G(N);
rep(_, M) {
int a, b;
in(a, b);
G[a].emplace_back(b), G[b].emplace_back(a);
}
LowLink LG(G);
sort(all(LG.bridges));
set<pii> S;
for (auto [a, b] : LG.bridges) {
if (a > b)
swap(a, b);
S.emplace(a, b);
}
for (auto [a, b] : S)
out(a, b);
}
| Env | Name | Status | Elapsed | Memory |
|---|---|---|---|---|
| g++ | 00_small_00 |
|
2 ms | 4 MB |
| g++ | 00_small_01 |
|
2 ms | 4 MB |
| g++ | 00_small_02 |
|
2 ms | 4 MB |
| g++ | 00_small_03 |
|
2 ms | 4 MB |
| g++ | 00_small_04 |
|
2 ms | 4 MB |
| g++ | 00_small_05 |
|
2 ms | 4 MB |
| g++ | 01_critical_00 |
|
2 ms | 4 MB |
| g++ | 01_critical_01 |
|
2 ms | 4 MB |
| g++ | 01_critical_02 |
|
2 ms | 4 MB |
| g++ | 01_critical_03 |
|
2 ms | 4 MB |
| g++ | 01_critical_04 |
|
2 ms | 4 MB |
| g++ | 01_critical_05 |
|
2 ms | 4 MB |
| g++ | 01_critical_06 |
|
2 ms | 4 MB |
| g++ | 01_critical_07 |
|
2 ms | 4 MB |
| g++ | 01_critical_08 |
|
2 ms | 4 MB |
| g++ | 01_critical_09 |
|
2 ms | 4 MB |
| g++ | 01_critical_10 |
|
2 ms | 4 MB |
| g++ | 01_critical_11 |
|
2 ms | 4 MB |
| g++ | 01_critical_12 |
|
2 ms | 4 MB |
| g++ | 02_grid_00 |
|
2 ms | 4 MB |
| g++ | 02_grid_01 |
|
2 ms | 4 MB |
| g++ | 02_grid_02 |
|
2 ms | 4 MB |
| g++ | 03_rand_00 |
|
2 ms | 4 MB |
| g++ | 03_rand_01 |
|
2 ms | 4 MB |
| g++ | 03_rand_02 |
|
2 ms | 4 MB |
| g++ | 03_rand_03 |
|
2 ms | 4 MB |
| g++ | 03_rand_04 |
|
2 ms | 4 MB |
| g++ | 03_rand_05 |
|
2 ms | 4 MB |
| g++ | 03_rand_06 |
|
2 ms | 4 MB |
| g++ | 03_rand_07 |
|
2 ms | 4 MB |
| g++ | 03_rand_08 |
|
3 ms | 4 MB |
| g++ | 03_rand_09 |
|
3 ms | 4 MB |
| g++ | 03_rand_10 |
|
3 ms | 4 MB |
| g++ | 03_rand_11 |
|
5 ms | 4 MB |
| g++ | 04_linear_00 |
|
2 ms | 4 MB |
| g++ | 04_linear_01 |
|
3 ms | 4 MB |
| g++ | 04_linear_02 |
|
8 ms | 6 MB |
| g++ | 04_linear_03 |
|
8 ms | 6 MB |
| g++ | 05_maximum_00 |
|
18 ms | 6 MB |
| g++ | 05_maximum_01 |
|
23 ms | 6 MB |
| clang++ | 00_small_00 |
|
2 ms | 4 MB |
| clang++ | 00_small_01 |
|
2 ms | 4 MB |
| clang++ | 00_small_02 |
|
2 ms | 4 MB |
| clang++ | 00_small_03 |
|
2 ms | 4 MB |
| clang++ | 00_small_04 |
|
2 ms | 4 MB |
| clang++ | 00_small_05 |
|
2 ms | 4 MB |
| clang++ | 01_critical_00 |
|
2 ms | 4 MB |
| clang++ | 01_critical_01 |
|
2 ms | 4 MB |
| clang++ | 01_critical_02 |
|
2 ms | 4 MB |
| clang++ | 01_critical_03 |
|
2 ms | 4 MB |
| clang++ | 01_critical_04 |
|
2 ms | 4 MB |
| clang++ | 01_critical_05 |
|
2 ms | 4 MB |
| clang++ | 01_critical_06 |
|
2 ms | 4 MB |
| clang++ | 01_critical_07 |
|
2 ms | 4 MB |
| clang++ | 01_critical_08 |
|
2 ms | 4 MB |
| clang++ | 01_critical_09 |
|
2 ms | 4 MB |
| clang++ | 01_critical_10 |
|
2 ms | 4 MB |
| clang++ | 01_critical_11 |
|
2 ms | 4 MB |
| clang++ | 01_critical_12 |
|
2 ms | 4 MB |
| clang++ | 02_grid_00 |
|
2 ms | 4 MB |
| clang++ | 02_grid_01 |
|
2 ms | 4 MB |
| clang++ | 02_grid_02 |
|
2 ms | 4 MB |
| clang++ | 03_rand_00 |
|
2 ms | 4 MB |
| clang++ | 03_rand_01 |
|
2 ms | 4 MB |
| clang++ | 03_rand_02 |
|
2 ms | 4 MB |
| clang++ | 03_rand_03 |
|
2 ms | 4 MB |
| clang++ | 03_rand_04 |
|
2 ms | 4 MB |
| clang++ | 03_rand_05 |
|
2 ms | 4 MB |
| clang++ | 03_rand_06 |
|
2 ms | 4 MB |
| clang++ | 03_rand_07 |
|
2 ms | 4 MB |
| clang++ | 03_rand_08 |
|
3 ms | 4 MB |
| clang++ | 03_rand_09 |
|
3 ms | 4 MB |
| clang++ | 03_rand_10 |
|
3 ms | 4 MB |
| clang++ | 03_rand_11 |
|
5 ms | 4 MB |
| clang++ | 04_linear_00 |
|
3 ms | 4 MB |
| clang++ | 04_linear_01 |
|
3 ms | 4 MB |
| clang++ | 04_linear_02 |
|
8 ms | 5 MB |
| clang++ | 04_linear_03 |
|
8 ms | 5 MB |
| clang++ | 05_maximum_00 |
|
18 ms | 5 MB |
| clang++ | 05_maximum_01 |
|
23 ms | 6 MB |