이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
struct ufind {
array<int, N> *c;
ufind(array<int, N> *c) : c(c) { iota(c->begin(), c->end(), 0); }
int find(int k) {
if ((*c)[k] == k) return k;
while ((*c)[k] != (*c)[(*c)[k]])
(*c)[k] = (*c)[(*c)[k]];
return (*c)[k];
}
void unite(int a, int b) { (*c)[find(a)] = find(b); }
};
struct edge { int to; int next; };
array<edge, 4*N> edges;
int edges_i = 0;
array<int, N> g;
int timer=0;
array<int, N> pre;
array<int, N> low;
bitset<2*N> evis;
void dfs(int v) {
pre[v] = low[v] = timer++;
for (;;) {
int e = g[v];
if (e == -1) return;
g[v] = edges[e].next;
int w = edges[e].to;
if (evis[e/2]) { continue; }
evis[e/2] = true;
if (pre[w] != -1) {
low[v] = min(low[v], pre[w]);
} else {
dfs(w);
low[v] = min(low[v], low[w]);
if (low[w] > pre[v]) {
cout << v+1 << ' ' << w+1 << '\n';
}
}
}
};
int main() {
fill(g.begin(), g.end(), -1);
int n, m; cin >> n >> m;
assert(n <= N);
{
array<ufind, 2> msts{{ufind(&pre), ufind(&low)}};
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);
edges[edges_i] = {b, g[a]};
g[a] = edges_i++;
edges[edges_i] = {a, g[b]};
g[b] = edges_i++;
break;
}
}
}
}
fill(pre.begin(), pre.end(), -1);
fill(low.begin(), low.end(), -1);
for (int i = 0; i < n; ++i)
if (pre[i] == -1)
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... |