-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10004.cpp
60 lines (55 loc) · 1.05 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
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#define foi( i, n , k ) for( int i = n ; i < k ; ++i)
using namespace std;
bool bfs( vector< vector<int> > &graph)
{
vector< bool >pas,color;
pas=color=vector<bool> (graph.size(),false);
queue<int> q;
q.push(0);
pas[0]=true;
color[0]=false;
while( !q.empty() )
{
int now=q.front();
q.pop();
foi( i , 0 , graph[now].size() )
{
int next=graph[now][i];
if( !pas[next] )
{
pas[next]=true;
color[next]=!color[now];
q.push(next);
}
else if( color[next]==color[now] )
return false;
}
}
return true;
}
int main()
{
int t;
while( scanf("%d",&t)!=EOF && t )
{
int n;
scanf("%d",&n);
vector< vector<int> > graph(t,vector<int>());
foi( i , 0 , n )
{
int a,b;
scanf("%d%d",&a,&b);
graph[a].push_back(b);
graph[b].push_back(a);
}
if( bfs(graph) )
printf("BICOLORABLE.\n" );
else
printf("NOT BICOLORABLE.\n" );
}
return 0;
};