-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBUGLIFE.cpp
More file actions
78 lines (76 loc) · 1.26 KB
/
BUGLIFE.cpp
File metadata and controls
78 lines (76 loc) · 1.26 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
69
70
71
72
73
74
75
76
77
78
#include<iostream>
#include<vector>
#include<queue>
#include<fstream>
using namespace std;
int main()
{
int T;
cin>>T;
for (int i = 1; i <= T; ++i)
{
int n,e;
cin>>n>>e;
vector<int> visited(n+1,0);
vector<char> gender(n+1,'N');
vector<vector<int> > adj(n+1, vector<int>(n+1));
int a=0,b=0;
for (int j = 1; j <= e; ++j)
{
cin>>a>>b;
adj[a][b] = 1;
adj[b][a] = 1;
}
queue<int> Q;
int flag = 0;
for (int r = 1; r <= n; ++r)
{
if(visited[r] == 0)
{
Q.push(r);
visited[r] = 1;
gender[r] = 'M';
while (!Q.empty())
{
int curr = Q.front();
Q.pop();
for (int s = 1; s <= n; ++s)
{
if (adj[curr][s] == 1)
{
if(visited[s] == 0)
{
Q.push(s);
visited[s] = 1;
if ( gender[curr] == 'M')
gender[s] = 'F';
else
gender[s] = 'M';
}
else
{
if(gender[curr] == gender[s])
{
cout<<"Scenario #"<<i<<":\n";
cout<<"Suspicious bugs found!\n";
flag = 1;
break;
}
}
}
}
if(flag == 1)
break;
}
}
if(flag == 1)
break;
}
if(flag != 1)
{
cout<<"Scenario #"<<i<<":\n";
cout<<"No suspicious bugs found!\n";
}
}
return 0;
}