-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBugLife_spoj.cpp
94 lines (74 loc) · 1.36 KB
/
BugLife_spoj.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
87
88
89
90
91
92
93
94
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
vector<int>*graph;
int *colored ;
int bipartite(int n,int i)
{
colored[i]=1 ;
queue<int>q;
q.push(i) ;
while(!q.empty())
{
int curr=q.front() ;
q.pop();
for(int j=0;j<graph[curr].size();j++)
{
int neigbor=graph[curr][j] ;
if(colored[neigbor]==-1)
{
colored[neigbor]=1-colored[curr] ;
q.push(neigbor);
}
else if(colored[curr]==colored[neigbor])
{
return 1;
}
}
}
return 0 ;
}
int main()
{
int t;
cin>>t;
int k=1 ;
while(t--){
int n;
cin>>n;
int m ;
cin>>m;
graph=new vector<int>[n+1] ;
while(m--)
{
int a,b ;
cin>>a>>b ;
graph[a].push_back(b) ;
graph[b].push_back(a) ;
}
colored=new int[n+1];
for(int i=1;i<=n;i++)
{
colored[i] =-1;
}
int flag=0;
cout<<"Scenario #"<<k<<":"<<endl;
for(int i=1;i<=n;i++)
{
if(colored[i]==-1){
// cout<<"okay"<<endl;
if(bipartite(n,i)==1)
{
flag=1 ;
cout<<"Suspicious bugs found!"<<endl;
break;
}
}
}
if(flag==0)
{
cout<<"No suspicious bugs found!"<<endl;
}
k++ ;
}
}