-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuva10004.cpp
79 lines (65 loc) · 1.36 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
using namespace std;
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cstdio>
int flag,n;
vector<int>graph[210];
int color[210];
void bfs(int s)
{
//memset(color,2,sizeof(color));
for(int i=0;i<n;i++)
color[i]=2;
queue<int>Q;
Q.push(s);
color[s]=0;
while(!Q.empty()&&flag)
{
int u = Q.front();
Q.pop();
for(int i=0;i<graph[u].size();i++)
{
if(color[graph[u][i]]==2)
{
// cout<<graph[u][i]<<endl;
Q.push(graph[u][i]);
color[graph[u][i]]=(color[u]+1)%2;
}
else
{
if(color[graph[u][i]]==color[u])
{
flag=0;
break;
}
}
}
}
}
int main()
{
int i,e,u,v;
while(scanf("%d",&n)==1)
{
if(n==0)
break;
scanf("%d",&e);
for(i=0;i<e;i++)
{
scanf("%d%d",&u,&v);
graph[u].push_back(v);
graph[v].push_back(u);
}
flag=1;
bfs(n-1);
if(flag)
printf("BICOLORABLE.\n");
else
printf("NOT BICOLORABLE.\n");
for(i=0;i<n;i++)
graph[i].clear();
}
return 0;
}