-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBUGLIFE.cpp
99 lines (86 loc) · 1.31 KB
/
BUGLIFE.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
95
96
97
98
99
#include<cstdio>
#include<list>
#include<queue>
using namespace std;
list<long int> *adj;
long int b;
long int *color;
void addEdge(long int u, long int v)
{
adj[u].push_back(v);
adj[v].push_back(u);
}
bool isBipartiite(long int num)
{
long int i,top;
for(i=0;i<b;i++)
color[i]=-1;
std::list<long int>::iterator it;
queue<long int>q;
color[num]=1;
q.push(num);
while(!q.empty())
{
top=q.front();
q.pop();
if(!adj[top].empty())
it=adj[top].begin();
else
continue;
while(it!=adj[top].end())
{
if(color[*it]==-1)
{
color[*it]=1-color[top];
q.push(*it);
}
else
if(color[*it]==color[top])
return false;
++it;
}
}
return true;
}
int main()
{
int t;
long int e,u,v,counter=1,i;
bool ans;
scanf("%d",&t);
while(t--)
{
scanf("%ld %ld",&b,&e);
adj=new list<long int>[b];
color=new long int [b];
while(e--)
{
scanf("%ld %ld",&u,&v);
addEdge(u-1,v-1);
}
ans=isBipartiite(0);
if(ans)
{
for(i=0;i<b;i++)
{
if(color[i]==-1)
ans=isBipartiite(i);
if(ans==false)
break;
}
}
if(ans)
{
printf("Scenario #%ld:\n",counter);
counter++;
printf("No suspicious bugs found!\n");
}
else
{
printf("Scenario #%ld:\n",counter);
counter++;
printf("Suspicious bugs found!\n");
}
}
return 0;
}