forked from joy-mollick/Problem-Solving-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HackerEarth- Rhezo and Destructive Mind.cpp
86 lines (77 loc) · 1.62 KB
/
HackerEarth- Rhezo and Destructive Mind.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=1e2+1;
bool vis[mx];
int disc[mx];
int low[mx];
int parent[mx];
bool ap[mx];
vector<int>adj[mx];
void apufind(int u)
{
static int time=0;
disc[u]=low[u]=time++;
int child=0;
vis[u]=true;
int i;
for(i=0;i<adj[u].size();i++)
{
int v=adj[u][i];
if(!vis[(v)]) {child++ ;
parent[v]=u ;
apufind(v);
low[u]=min(low[u],low[v]);
if(parent[u]==-1 && child>1)
{
ap[u]=true; // root
}
if( parent[u]!=-1 && low[v]>=disc[u])
{
ap[u]=true; // there is a back edge if it is disconnected , so connected component will be increased
}
}
else if(parent[u]!=v)
{
low[u]=min(low[u],disc[v]);
}
}
}
int main()
{
int n,m,q,a,b,index;
cin>>n>>m;
while(m--)
{
cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
for(int i=0;i<=n;i++)
{
parent[i]=-1;
vis[i]=false;
ap[i]=false;
}
for(int i=1;i<=n;i++)
{
if(vis[i]==false)
{
apufind(i);
}
}
cin>>q;
while(q--)
{
cin>>index;
int ans= (int) (adj[index].size());// when one point is articulation point , if it removes - connected to it will be disconnected
if(ap[index])
{
cout<<"Satisfied "<<ans<<endl;
}
else
{
cout<<"Not Satisfied"<<endl;
}
}
return 0;
}