This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct ufind {
vector<int> c;
ufind(int n) : c(n) { iota(c.begin(), c.end(), 0); }
int find(int k) { return c[k] == k ? k : (c[k] = find(c[k])); }
void unite(int a, int b) { c[find(a)] = find(b); }
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m; cin >> n >> m;
vector<vector<pair<int, int>>> g(n);
array<ufind, 2> msts{{ufind(n), ufind(n)}};
for (int i = 0; i < m; ++i) {
int a, b; cin >> a >> b; --a; --b;
for (auto& mst : msts) {
if (mst.find(a) != mst.find(b)) {
mst.unite(a, b);
g[a].emplace_back(b, i);
g[b].emplace_back(a, i);
break;
}
}
}
vector<pair<int, int>> bridges;
vector<bool> visited(n);
vector<int> pre(n, -1), low(n, -1);
int timer=0;
auto dfs = [&](auto&& self, int v, int e = -1) -> void {
visited[v] = true;
pre[v] = low[v] = timer++;
for (auto [w, f] : g[v]) {
if (f == e) continue;
if (visited[w]) {
low[v] = min(low[v], pre[w]);
} else {
self(self, w, f);
low[v] = min(low[v], low[w]);
if (low[w] > pre[v]) {
cout << v+1 << ' ' << w+1 << '\n';
}
}
}
};
for (int i = 0; i < n; ++i)
if (!visited[i])
dfs(dfs, i);
}
Compilation message (stderr)
pipes.cpp: In lambda function:
pipes.cpp:39:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
39 | for (auto [w, f] : g[v]) {
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |