-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSpoj_Bugs_Life.cpp
More file actions
68 lines (62 loc) · 1.39 KB
/
Spoj_Bugs_Life.cpp
File metadata and controls
68 lines (62 loc) · 1.39 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
#include <bits/stdc++.h>
using namespace std;
#define ll long int
vector<int > adj[100005];
int vis[100005]={0};
int color[100005];
bool dfs(int u,int c){
color[u]=c;
vis[u]=1;
for(auto i:adj[u]){
if(vis[i]==0){
bool res=dfs(i,c^1);
//result returned by already visited node
if(res==false){
return false;
}
}
else{
//if its already visited
if(color[u]==color[i])
return false;
}
}
return true;
}
int main() {
int n,t,m;
cin>>t;
for(int i=1;i<=t;i++){
memset(vis,0,sizeof(vis));
memset(color,-1,sizeof(color));
for(int i=0;i<2005;i++){
adj[i].clear();
}
cin>>n>>m;
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
adj[x].push_back(y);
adj[y].push_back(x);
}
//as question contain various connected components
bool b,flag=true;
for(int i=1;i<=n;i++){
if(!vis[i]){
b=dfs(i,0);
if(b==false){
flag=false;
}
}
}
if(flag==false){
cout<<"Scenario #"<<i<<":"<<endl;
cout<<"Suspicious bugs found!"<<endl;
}
else{
cout<<"Scenario #"<<i<<":"<<endl;
cout<<"No suspicious bugs found!"<<endl;
}
}
return 0;
}