File size: 1,135 Bytes
c4b0eef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 200;
const int GRAY = -1;
const int WHITE = 0;
const int BLACK = 1;
vector <int> v[MAXN+2];
int color[MAXN+2];

bool dfs( int node, int c ) {
    if( color[node] == (1 - c) ) {
        return false;
    }
    if( color[node] == c ) {
        return true;
    }
    color[node] = c;
    bool ret = true;
    for( int i = 0 ; (i < v[node].size()) && ret ; ++i ) {
        int now = v[node][i];
        ret &= dfs( now, (1 - c) );
    }
    return ret;
}

int main( int argc, char ** argv ) {
    int n, e;
    while( scanf( "%d", &n ) == 1 && n ) {
        scanf( "%d", &e );
        for( int i = 1 ; i <= e ; ++i ) {
            int x, y;
            scanf( "%d %d", &x, &y );
            v[x].push_back( y );
            v[y].push_back( x );
        }

        memset( color, GRAY, sizeof( color ) );
        bool flag = dfs( 0, WHITE );
        if( flag ) {
            puts( "BICOLORABLE." );
        }
        else {
            puts( "NOT BICOLORABLE." );
        }

        for( int i = 0 ; i < n ; ++i ) {
            v[i].clear();
        }
    }
    return 0;
}