forked from IElgohary/Uva-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10004-Bicoloring.cpp
executable file
·71 lines (55 loc) · 1.16 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
64
65
66
67
68
69
70
71
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector<int> arr[200];
int n;
bool bfs(int source )
{
queue<int> q;
q.push(source);
int color[200];
fill( color , color + n ,-1);
while(!q.empty())
{
int u = q.front();
q.pop();
for ( int i = 0 ; i < arr[u].size() ; i++)
{
int v = arr[u][i];
if ( color[v] == -1 )
{
color[v] = 1 - color[u];
q.push(v);
}
if ( color [v] == color[u])
return false;
}
}
return true;
}
int main()
{
while ( true)
{
for ( int i = 0 ; i < 200 ; i++)
arr[i].clear();
cin >> n;
if ( n == 0)
break;
int l;
cin >> l;
while (l--)
{
int a , b;
cin >> a>> b;
arr[a].push_back(b);
arr[b].push_back(a);
}
if ( bfs(0))
cout << "BICOLORABLE."<<endl;
else
cout << "NOT BICOLORABLE."<<endl;
}
return 0;
}