#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 |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1108 KB |
Output is correct |
2 |
Correct |
7 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
270 ms |
16344 KB |
Output is correct |
2 |
Correct |
271 ms |
15164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
508 ms |
22876 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
874 ms |
43852 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1181 ms |
53080 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1623 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2391 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1866 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1767 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |