-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridgegraph.cpp
More file actions
52 lines (49 loc) · 756 Bytes
/
bridgegraph.cpp
File metadata and controls
52 lines (49 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
int t=0;
void dfs(vector<int>list[],int sv,int p,bool *vis,int *tim,int *low)
{
vis[sv]=1;
tim[sv]=low[sv]=++t;
for(auto to:list[sv])
{
if(to==p) continue;
if(vis[to])
{
low[sv]=min(low[sv],tim[to]);
}
else
{
dfs(list,to,sv,vis,tim,low);
low[sv]=min(low[sv],low[to]);
if(low[to]>tim[sv])
{
cout<<sv<<" "<<to<<endl;
}
}
}
}
int main()
{
int n,m;
cin>>n>>m;
vector<int>list[n+1];
for(int i=0;i<m;i++)
{
int u,v;
cin>>u>>v;
list[u].push_back(v);
list[v].push_back(u);
}
int *tim=new int[n+1];
int *low=new int[n+1];
for(int i=0;i<n+1;i++)
{
tim[i]=0;
low[i]=0;
}
bool *vis=new bool[n]();
int sv;
cin>>sv;
dfs(list,sv,-1,vis,tim,low);
}