이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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<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].push_back(b);
g[b].push_back(a);
break;
}
}
}
vector<pair<int, int>> bridges;
vector<bool> visited(n);
vector<int> tin(n), low(n);
int timer=0;
auto dfs = [&](auto&& self, int v, int p = -1) -> void {
visited[v] = true;
tin[v] = low[v] = timer++;
for (int to : g[v]) {
if (to == p) continue;
if (visited[to]) {
low[v] = min(low[v], tin[to]);
} else {
self(self, to, v);
low[v] = min(low[v], low[to]);
if (low[to] > tin[v]) {
cout << v+1 << ' ' << to+1 << '\n';
}
}
}
};
for (int i = 0; i < n; ++i)
if (!visited[i])
dfs(dfs, i);
}
# | 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... |