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;
const int MAX = 70010;
const int INF = 0x3f3f3f3f;
int n, m, pre[MAX], low[MAX], timer;
bool seen[MAX];
vector<int> adj[MAX];
vector<pair<int, int>> bridges;
void dfs(int u, int p)
{
seen[u] = true;
pre[u] = low[u] = ++timer;
for(auto v : adj[u])
{
if(v == p) continue;
if(!seen[v])
{
dfs(v, u);
low[u] = min(low[u], low[v]);
}else{
low[u] = min(low[u], pre[v]);
}
if(low[v] > pre[u]) bridges.emplace_back(u, v);
}
}
int32_t main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
while(m--)
{
int u, v; cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i = 1; i <= n; i++)
if(!seen[i]) dfs(i, i);
for(auto [u, v] : bridges)
cout << u << ' ' << v << '\n';
}
# | 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... |