forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
10004.cpp
91 lines (83 loc) · 1.24 KB
/
10004.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int(i) = int(a); (i) < int(b); (i)++)
#define FOREQ(i, a, b) for (int(i) = int(a); (i) <= int(b); (i)++)
#define MAXN 202
struct SS {char color;} V[MAXN];
static char Link[MAXN][MAXN];
static int a, b, s, N, E, Q[MAXN], QH, QT;
inline void push(int n)
{
Q[QH++] = n;
QH %= MAXN;
}
inline int pop()
{
int n = Q[QT++];
QT %= MAXN;
return n;
}
inline bool is_empty_()
{
return QH == QT;
}
inline int BFS(int s)
{
int u;
char co;
V[s].color = 'w';
QH = QT = 0;
push(s);
while (!is_empty_())
{
u = pop();
co = 'w';
if (V[u].color == 'w')
{
co = 'b';
}
FOR(i, 0, N)
{
if (Link[i][u] == 1)
{
if (V[i].color == 'g')
{
V[i].color = co;
Link[i][u] = Link[u][i] = 0;
push(i);
}
else if (V[i].color == V[u].color)
{
return 0;
}
}
}
}
return 1;
}
int main()
{
while (scanf("%d", &N) && N)
{
scanf("%d", &E);
FOR(i, 0, E)
{
scanf("%d%d", &a, &b);
Link[a][b] = Link[b][a] = 1;
s = a;
}
FOREQ(i, 0, N)
V[i].color = 'g';
if (BFS(s))
{
printf("BICOLORABLE.\n");
}
else
{
printf("NOT BICOLORABLE.\n");
}
FOR(i, 0, MAXN)
memset(Link[i], 0, 201 * sizeof(char));
}
return 0;
}