forked from joy-mollick/Problem-Solving-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPOJ-BUGLIFE - A Bug’s Life.cpp
83 lines (74 loc) · 1.47 KB
/
SPOJ-BUGLIFE - A Bug’s Life.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
#include <bits/stdc++.h>
using namespace std;
const int mx=1e6+1;
vector<int>adj[mx];
int color[mx];
bool possible(int source)
{
queue<int>q;
q.push(source);
color[source]=0;
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=0;i<adj[u].size();i++)
{
int v=adj[u][i];
if(color[v]==-1)
{
if(color[u]==0)
color[v]=1;
else
color[v]=0;
q.push(v);
}
if(color[u]==color[v])
return false;
}
}
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tc,n,m,a,b;
cin>>tc;
int r=1;
while(tc--)
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
color[i]=-1;
adj[i].clear();
}
while(m--)
{
cin>>a>>b;
adj[a].push_back(b);
adj[b].push_back(a);
}
cout<<"Scenario #"<<r<<":"<<endl;
bool ok=true;
for(int j=1;j<=n;j++)
{
if(color[j]==-1){
if(!possible(j))
{
ok=false;
break;
}
}
}
if(ok)
{
cout<<"No suspicious bugs found!"<<endl;
}
else
cout<<"Suspicious bugs found!"<<endl;
r++;
}
}