-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstrConCom.cpp
More file actions
75 lines (69 loc) · 1.2 KB
/
strConCom.cpp
File metadata and controls
75 lines (69 loc) · 1.2 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
//strConCom.cpp
#include <bits/stdc++.h>
#define INF 100000000
#define F first
#define S second
using namespace std;
int parent[100];
int disc[100];
int low[100];
bool vis[100];
bool ap[100];
vector <int> adj[100];
stack <int> stk;
void dfs(int vertex,int time){
int u,child=0;
vis[vertex]=true;
stk.push(vertex);
disc[vertex]=time+1;
low[vertex]=time+1;
for(int i=0;i<adj[vertex].size();i++){
u=adj[vertex][i];
if(vis[u]==false){
child++;
parent[u]=vertex;
dfs(u,time+1);
low[vertex]=min(low[vertex],low[u]);
if(parent[vertex]==-1 && child>1)
ap[vertex]=true;
else if(parent[vertex]!=-1 && disc[vertex] <=low[u])
ap[vertex]=true;
}
else if(parent[vertex]!=u ){
low[vertex]=min(low[vertex],disc[u]);
}
}
if(low[vertex]==disc[vertex]){
u=stk.top();
while(u!=vertex){
cout<<u<<" ";
stk.pop();
u=stk.top();
}
cout<<u<<endl;
stk.pop();
}
}
int main(){
int n,m,i,a,b,j;
cin>>n>>m;
for(i=0;i<m;i++){
cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for(i=0;i<=n;i++){
vis[i]=false;
low[i]=INF;
ap[i]=false;
}
for(i=1;i<=n;i++){
if(vis[i]==false){
parent[i]=-1;
dfs(i,0);
}
}
for(i=1;i<=n;i++){
cout<<i<<" "<<ap[i]<<endl;
}
}