-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva10004.cpp
111 lines (76 loc) · 1.31 KB
/
uva10004.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
92
93
94
95
96
97
#include <cstdio>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <limits.h>
#include <list>
#include <queue>
#include <map>
#define TRvi(c, it) \
for(vector<int>::iterator it = c.begin(); it != c.end(); it++)
#define BFS_WHITE -1
using namespace std;
int N;
vector<vector<int> > AdjList; /* connected graph */
int colour[220];
int curent_colour;
bool bipartite_check()
{
queue<int> q, empty;
q.push(0);
curent_colour = 0;
colour[0] = curent_colour;
bool verify = true;
while(!q.empty())
{
int u = q.front();
q.pop();
TRvi(AdjList[u], v)
{
if(colour[*v] == BFS_WHITE)
{
q.push(*v);
colour[*v] = 1 - colour[u];
}
else
{
if(colour[*v] == colour[u])
{
verify = false;
break;
}
}
}
}
return verify;
}
int main()
{
int l;
int src, dest;
while(true)
{
cin >> N;
if(N == 0)
break;
cin >> l;
AdjList.clear();
memset(colour, BFS_WHITE, sizeof(colour));
AdjList.resize(N);
for(int i = 0; i < l; i++)
{
cin >> src >> dest;
AdjList[src].push_back(dest);
AdjList[dest].push_back(src);
}
int verify = bipartite_check();
if(verify)
cout << "BICOLORABLE." << endl;
else
cout << "NOT BICOLORABLE." << endl;
}
return 0;
}