-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10004 - Bicoloring.cpp
59 lines (57 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
#include<cstdio>
#include<queue>
#include<iostream>
#include<vector>
using namespace std;
vector <int>graph[200];
int bfs(int node)
{
int color[200]={0};
int visit[200]={0};
queue <int> q;
q.push(node);
color[node]=1;
while (!q.empty())
{
int f=q.front();
q.pop();
int d=color[f]==1?2:1;
int l=graph[f].size();
for (int i=0;i<l;i++)
{
node=graph[f][i];
if (color[f]==color[node]) return 0;
if (!visit[node])
{
q.push(node);
color[node]=d;
visit[node]=1;
}
}
}
return 1;
}
int main()
{
int n,e,u,v;
while (1)
{
cin>>n;
if (n==0)
break;
cin>>e;
for (int i=0;i<e;i++)
{
cin>>u>>v;
graph[u].push_back(v);
graph[v].push_back(u);
}
if (bfs(0))
cout<<"BICOLORABLE."<<endl;
else
cout<<"NOT BICOLORABLE."<<endl;
for (int i=0;i<n;i++)
graph[i].clear();
}
return 0;
}