이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 1e5;
int n, m;
int low[N], num[N];
vector<int> g[N];
struct dsu {
int pr[N];
dsu() {
memset(pr, -1, sizeof(pr));
}
int find(int u) {
return pr[u] < 0 ? u : pr[u] = find(pr[u]);
}
bool mrg(int u, int v) {
int a = find(u), b = find(v);
if (a == b) {
return 0;
}
pr[b] = a;
g[u].push_back(v);
g[v].push_back(u);
return 1;
}
} a, b;
int timer;
void dfs(int u, int p) {
low[u] = num[u] = ++timer;
bool flg = 0;
for (int v : g[u]) {
if (v == p && !flg) {
flg = 1;
continue;
}
if (!num[v]) {
dfs(v, u);
low[u] = min(low[u], low[v]);
if (low[v] > num[u]) {
cout << u + 1 << " " << v + 1 << "\n";
}
} else {
low[u] = min(low[u], num[v]);
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
while (m--) {
int u, v; cin >> u >> v; --u, --v;
if (!a.mrg(u, v)) {
b.mrg(u, v);
}
}
for (int i = 0; i < n; ++i) {
if (!num[i]) {
dfs(i, i);
}
}
return 0;
}
# | 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... |