-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathBUGLIFE.cpp
More file actions
51 lines (51 loc) · 1.42 KB
/
Copy pathBUGLIFE.cpp
File metadata and controls
51 lines (51 loc) · 1.42 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
// Ivan Carvalho
// Solution to https://www.spoj.com/problems/BUGLIFE/
#include <cstdio>
#include <queue>
#include <vector>
#define MAXN 2010
using namespace std;
vector<int> grafo[MAXN];
int cor[MAXN], TC, n, m;
int main() {
scanf("%d", &TC);
for (int tc = 1; tc <= TC; tc++) {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
grafo[i].clear();
cor[i] = -1;
}
while (m--) {
int u, v;
scanf("%d %d", &u, &v);
grafo[u].push_back(v);
grafo[v].push_back(u);
}
int isBipartite = 1;
for (int i = 1; i <= n; i++) {
if (cor[i] == -1) {
cor[i] = 1;
queue<int> bfs;
bfs.push(i);
while (!bfs.empty()) {
int v = bfs.front();
bfs.pop();
for (int u : grafo[v]) {
if (cor[u] == -1) {
cor[u] = 1 - cor[v];
bfs.push(u);
} else if (cor[u] == cor[v]) {
isBipartite = 0;
}
}
}
}
}
printf("Scenario #%d:\n", tc);
if (isBipartite)
printf("No suspicious bugs found!\n");
else
printf("Suspicious bugs found!\n");
}
return 0;
}