-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path10004 - Bicoloring.cpp
64 lines (50 loc) · 1.04 KB
/
10004 - Bicoloring.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
#include <stdio.h>
#include <vector>
#include <queue>
#include <memory.h>
using namespace std;
int const N = 201;
int n, m, color[N];
vector<vector<int> > g;
queue<int> q;
bool checkBipartite(int src) {
memset(color, -1, sizeof color);
color[src] = 0;
while(!q.empty()) q.pop();
q.push(src);
int size, fr;
while(!q.empty()) {
size = q.size();
while(size-- > 0) {
fr = q.front();
q.pop();
for(int i = 0; i < g[fr].size(); ++i) {
if(color[g[fr][i]] == color[fr])
return false;
if(color[g[fr][i]] == -1) {
color[g[fr][i]] = 1 - color[fr];
q.push(g[fr][i]);
}
}
}
}
return true;
}
int main() {
while(scanf("%d", &n) && n != 0) {
g.clear();
g.resize(n);
scanf("%d", &m);
int a, b;
while(m-- > 0) {
scanf("%d%d", &a, &b);
g[a].push_back(b);
g[b].push_back(a);
}
if(checkBipartite(0))
puts("BICOLORABLE.");
else
puts("NOT BICOLORABLE.");
}
return 0;
}