forked from joy-mollick/Problem-Solving-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPOJ-EC_P - Critical Edges.cpp
86 lines (77 loc) · 1.67 KB
/
SPOJ-EC_P - Critical Edges.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<bits/stdc++.h>
using namespace std;
const int mx=700;
typedef pair<int,int> pi;
vector<pi>ans;
vector<int>adj[mx];
int low[mx];
int disc[mx];
int parent[mx];
bool visited[mx];
int s,t;
void apufind(int u)
{
static int time=0;
int child=0;
visited[u]=true;
disc[u]=low[u]=++time;
int it;
for(it=0;it<adj[u].size();it++)
{
int v=adj[u][it];
if(!visited[v])
{
child++;
parent[v]=u;
apufind(v);
low[u]=min(low[u],low[v]);
if(low[v]>disc[u]) {ans.push_back(make_pair(min(u,v),max(u,v)));}
}
else if(v!=parent[u])
{
low[u]=min(low[u],disc[v]);
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tc,n,m,k,a,b,c;
cin>>tc;
for(int l=1;l<=tc;l++)
{
cout<<endl;
cout<<"Caso #"<<l<<endl;
cin>>n>>m;
s++,t++;
for(int i=1;i<=n;i++)
{
adj[i].clear();
low[i]=0;
disc[i]=0;
parent[i]=-1;
visited[i]=false;
ans.clear();
}
while(m--)
{
cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
apufind(1);
if(ans.size()==0)
cout<<"Sin bloqueos"<<endl;
else{
cout<<ans.size()<<endl;
sort(ans.begin(),ans.end());
for(int m=0;m<ans.size();m++)
{
cout<<ans[m].first<<" "<<ans[m].second<<endl;
}
}
}
return 0;
}