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;
int n, m;
vector<vector<int>> ad;
vector<int> low, num;
int it;
void dfs(int u, int p = -1) {
low[u] = num[u] = ++it;
for (const auto& v : ad[u]) {
if (v == p) continue;
if (!low[v]) {
dfs(v, u);
low[u] = min(low[u], low[v]);
if (low[v] == num[v]) cout << u << " " << v << "\n";
} else low[u] = min(low[u], num[v]);
}
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
ad = vector<vector<int>> (n + 1);
for (int i = 1; i <= m; ++i) {
int u, v; cin >> u >> v;
ad[u].push_back(v);
ad[v].push_back(u);
}
low = num = vector<int>(n + 1);
for (int i = 1; i <= n; ++i) if (!low[i]) 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... |