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 <iostream>
#include <vector>
using namespace std;
#define pii pair<int,int>
vector<pii> ans;
int timer=0;
int dfs(int a,int par,vector<vector<pii>>& g,vector<int>& min_in,vector<int>& t){
t[a]=timer++;
min_in[a]=t[a];
for(auto x:g[a]){
if(x.second==par)continue;
if(t[x.first]==-1){
int up=dfs(x.first,x.second,g,min_in,t);
if(up>t[a])ans.push_back({a+1,x.first+1});
}
min_in[a]=min(min_in[a],min_in[x.first]);
}
//cout<<a<<' '<<min_in[a]<<' '<<t[a]<<'\n';
return min_in[a];
}
int main(){
int n,m,x,y;
cin>>n>>m;
vector<vector<pair<int,int>>> g(n,vector<pair<int,int>>());
vector<int> t(n,-1),min_in(n);
for(int i=0;i<m;i++){
cin>>x>>y;
x--;y--;
g[x].push_back({y,i});
g[y].push_back({x,i});
}
for(int i=0;i<n;i++)if(t[i]==-1)dfs(i,-1,g,min_in,t);
//cout<<endl;
for(auto x:ans)cout<<x.first<<' '<<x.second<<'\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... |