#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<int>>& g,vector<int>& min_in,vector<int>& t){
t[a]=timer++;
min_in[a]=t[a];
for(int x:g[a]){
if(x==par)continue;
if(t[x]==-1){
int up=dfs(x,a,g,min_in,t);
if(up>t[a])ans.push_back({a+1,x+1});
}
min_in[a]=min(min_in[a],min_in[x]);
}
//cout<<a<<' '<<min_in[a]<<' '<<t[a]<<'\n';
return min_in[a];
}
int main(){
int n,m,x,y;
cin>>n>>m;
vector<vector<int>> g(n,vector<int>());
vector<int> t(n,-1),min_in(n);
while(m--){
cin>>x>>y;
x--;y--;
g[x].push_back(y);
g[y].push_back(x);
}
for(int i=0;i<n;i++)if(t[i]==-1)dfs(i,i,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 |
Incorrect |
1 ms |
212 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
988 KB |
Output is correct |
2 |
Incorrect |
6 ms |
596 KB |
Wrong number of edges |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
268 ms |
8572 KB |
Output is correct |
2 |
Correct |
266 ms |
7816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
472 ms |
12368 KB |
Output is correct |
2 |
Runtime error |
567 ms |
28032 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
809 ms |
24324 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1184 ms |
32864 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1881 ms |
65536 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2570 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3198 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3458 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |