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>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
int n, m;
vector<int> G[100010];
vector<bool> vis;
vi tin, low;
int timer;
vector<pii> ans;
void dfs(int node, int parent = -1){
vis[node] = true;
tin[node] = low[node] = timer++;
for(auto next : G[node]){
if(next == parent) continue;
if(vis[next]){
low[node] = min(low[node], tin[next]);
}
else{
dfs(next, node);
low[node] = min(low[node], low[next]);
if(low[next] > tin[node]){
ans.pb(mp(node,next));
}
}
}
}
void init(){
timer = 0;
vis.assign(n, false);
tin.assign(n, -1);
low.assign(n, -1);
for(int i = 0; i < n; i++){
if(!vis[i])
dfs(i);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i = 0; i < m; i++){
int a, b;
cin>>a>>b;
a--; b--;
G[a].pb(b);
G[b].pb(a);
}
init();
for(int i = 0; i < ans.size(); i++)
{
cout<<ans[i].first+1<<" "<<ans[i].second+1<<endl;
}
}
Compilation message (stderr)
pipes.cpp: In function 'int main()':
pipes.cpp:56:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = 0; i < ans.size(); i++)
| ~~^~~~~~~~~~~~
# | 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... |