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;
#define endl "\n"
typedef long long int ll;
const int MOD = 1e9 + 7;
vector<pair<int, int>> pipes;
int cnt = 1;
void DFS(int x, vector<vector<pair<int, int>>>& adj, vector<int>& vis, vector<int>& mn, int edge){
vis[x] = cnt; mn[x] = cnt; cnt++;
for(pair<int, int> pr : adj[x]){
int node = pr.first;
if(pr.second == edge) continue;
if(vis[node] > 0){
mn[x] = min(mn[x], vis[node]);
}else{
DFS(node, adj, vis, mn, pr.second);
mn[x] = min(mn[x], mn[node]);
if(mn[node] > vis[x]){
pipes.push_back({node, x});
}
}
}
}
void solve(){
int n, m; cin >> n >> m;
vector<vector<pair<int, int>>> adj(n);
for(int i = 0; i < m; i++){
int u, v; cin >> u >> v; u--; v--;
adj[u].push_back({v, i}); adj[v].push_back({u, i});
}
vector<int> vis(n, 0);
vector<int> mn(n, 0);
for(int i = 0; i < n; i++){
if(!vis[i]){
DFS(i, adj, vis, mn, -1);
}
}
for(auto p : pipes) cout << p.first + 1 << " " << p.second + 1 << endl;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//~ int tt; cin >> tt;
int tt = 1;
for(int t = 1; t <= tt; t++){
solve();
}
}
# | 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... |