-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path796.cpp
More file actions
executable file
·92 lines (75 loc) · 1.53 KB
/
796.cpp
File metadata and controls
executable file
·92 lines (75 loc) · 1.53 KB
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
87
88
89
90
91
92
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adj;
vector<bool> visited;
vector<int> fup,tin;
int timer;
int count,n;
vector<pair<int,int>> ans;
void dfs(int v,int p=-1)
{
visited[v]=true;
fup[v]=tin[v]=timer++;
for(int u: adj[v])
{
if(u==p)continue;
else if(visited[u])
{
fup[v]=min(fup[v],tin[u]);
}
else{
dfs(u,v);
fup[v]=min(fup[v],fup[u]);
if(fup[u]>tin[v])
{
ans.push_back(make_pair(min(u,v),max(u,v)));
}
}
}
}
void finding_bridges()
{
timer=0;
visited.assign(n,false);
ans.clear();
tin.assign(n,-1);
fup.assign(n,-1);
for(int i=0; i<n; i++)
{
if(!visited[i])dfs(i);
}
}
int main()
{
while(cin>>n)
{
adj.resize(n+1);
int e,aa,it,bb;
string bichme;
for(int i=0; i<n;i++)
{
cin>>aa;
cin>>bichme;
string no;
no=bichme.substr(1,bichme.size()-2);
it=stoi(no);
for(int l=0; l<it; l++)
{
cin>>bb;
adj[aa].push_back(bb);
adj[bb].push_back(aa);
}
}
finding_bridges();
sort(ans.begin(),ans.end());
cout<<ans.size()<<" critical links"<<endl;
for(int i=0; i<ans.size(); i++)
{
cout<<ans[i].first<<" - "<<ans[i].second<<endl;
}
cout<<endl;
string havana;
getline(cin,havana);
adj.clear();
}
}