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>
#include <algorithm>
using namespace std;
int n,m;
int ind[100001];
int lo[100001];
bool vis[600001];
vector<vector<pair<int,int> > > v;
int broj=1;
void dfs(int x,int pr)
{
ind[x]=broj;
lo[x]=broj;
broj++;
for(int i=0;i<v[x].size();i++)
{
if(v[x][i].second==pr)
continue;
if(ind[v[x][i].first]==0)
{
dfs(v[x][i].first,v[x][i].second);
lo[x]=min(lo[x],lo[v[x][i].first]);
if(lo[v[x][i].first]>ind[x])
vis[v[x][i].second]=true;
}
else
lo[x]=min(lo[x],ind[v[x][i].first]);
}
}
int main()
{
cin>>n;
cin>>m;
vector<pair<int,int> > vec;
vector<int> s,e;
v.insert(v.begin(),2*(n+m+4),vec);
for(int i=0;i<m;i++)
{
int a,b;
cin>>a>>b;
a--;
b--;
s.push_back(a);
e.push_back(b);
v[a].push_back(make_pair(b,i));
v[b].push_back(make_pair(a,i));
}
dfs(0,-1);
for(int i=0;i<m;i++)
{
if(vis[i])
cout<<s[i]+1<<" "<<e[i]+1<<endl;
}
cout<<endl;
return 0;
}
/*
9 11
1 2
2 3
3 1
3 4
4 5
5 6
6 4
6 7
7 8
8 9
9 7
*/
Compilation message (stderr)
pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:16:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[x].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... |