-
Notifications
You must be signed in to change notification settings - Fork 0
/
BUGLIFE-a_bugs_life.cpp
65 lines (54 loc) · 1.12 KB
/
BUGLIFE-a_bugs_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
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
enum { NONE = 0, RED = 1, BLACK = 2 };
short nodes[2001];
inline short inv(short color) { return color == RED ? BLACK : RED; }
bool bipartite(vector<vi>& graph, int node) {
queue<int> q;
q.push(node);
nodes[node] = RED;
while (!q.empty()) {
int u = q.front();
q.pop();
for (int v : graph[u]) {
if (nodes[v] == NONE) {
nodes[v] = inv(nodes[u]);
q.push(v);
} else if (nodes[v] == nodes[u]) {
return false;
}
}
}
return true;
}
void solve() {
memset(nodes, NONE, sizeof nodes);
int n, m;
cin >> n >> m;
vector<vi> g(n);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
g[u].push_back(v);
g[v].push_back(u);
}
for (int i = 0; i < n; i++) {
if (nodes[i] != NONE) continue;
if (!bipartite(g, i)) {
cout << "Suspicious bugs found!" << endl;
return;
}
}
cout << "No suspicious bugs found!" << endl;
}
int main() {
int T;
cin >> T;
for (int i = 0; i < T; i++) {
printf("Scenario #%d:\n", i + 1);
solve();
}
}