-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathBUGLIFE.cpp
61 lines (53 loc) · 1.34 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
/*
graphs > specials > bipartite > bipartite checking
difficulty: easy
date: 19/Aug/2020
hint: check all connect components
by: @brpapa
*/
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj_list; int V;
enum { WHITE, BLACK, WITHOUT_COLOR };
vector<int> state;
bool bfs(int s) {
state[s] = WHITE;
queue<int> q; q.push(s);
bool isBipartite = true;
while (!q.empty() && isBipartite) {
int u = q.front(); q.pop();
for (int v : adj_list[u]) {
if (state[v] == WITHOUT_COLOR) {
state[v] = (state[u]+1) % 2;
q.push(v);
}
else if (state[v] == state[u]) { // conflito de cor
isBipartite = false;
}
}
}
return isBipartite;
}
int main() {
int T, t = 1; cin >> T;
while (T--) {
int E; cin >> V >> E;
adj_list.assign(V, vector<int>());
while (E--) {
int u, v; cin >> u >> v; u--; v--;
adj_list[u].push_back(v);
adj_list[v].push_back(u);
}
bool isBipartite = true;
state.assign(V, WITHOUT_COLOR);
for (int root = 0; root < V; root++)
if (state[root] == WITHOUT_COLOR)
if (!bfs(root)) {
isBipartite = false;
}
printf("Scenario #%d:\n", t++);
if (!isBipartite) cout << "Suspicious bugs found!\n";
else cout << "No suspicious bugs found!\n";
}
return 0;
}