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; // number of nodes
vector<vector<int>> adj; // adjacency list of graph
vector<bool> visited;
vector<int> tin, fup;
int timer;
void dfs(int v, int p = -1) {
visited[v] = true;
tin[v] = fup[v] = timer++;
for (int to : adj[v]) {
if (to == p) continue;
if (visited[to]) {
fup[v] = min(fup[v], tin[to]);
} else {
dfs(to, v);
fup[v] = min(fup[v], fup[to]);
if (fup[to] > tin[v])
cout << v + 1 << ' ' << to + 1 << endl;
}
}
}
void find_bridges() {
timer = 0;
visited.assign(n, false);
tin.assign(n, -1);
fup.assign(n, -1);
for (int i = 0; i < n; ++i) {
if (!visited[i])
dfs(i);
}
}
int main(){
cin >> n; int M; cin >> M;
adj.resize(n);
for (int i = 0; i < M; i++){
int u, v; cin >> u >> v;
u--; v--; adj[u].push_back(v); adj[v].push_back(u);
}
find_bridges();
}
# | 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... |