-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path10004.cpp
executable file
·60 lines (50 loc) · 1004 Bytes
/
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 <vector>
using namespace std ;
#define MaxN 200
vector<int> neighbor[ MaxN ] ;
int colorMap[ MaxN ] = { 0 } ;
int solved = true ;
void dfs( int n, int color )
{
int i = 0 ;
if( colorMap[ n ] == -1 )
{
colorMap[ n ] = color ;
for( i = 0 ; i < neighbor[ n ].size() ; i++ )
dfs( neighbor[ n ][ i ], 1 - color ) ;
}
else
{
if( colorMap[ n ] != color )
solved = false ;
}
}
int main()
{
int n = 0 ;
int m = 0 ;
int a = 0 ;
int b = 0 ;
int i = 0 ;
while( cin >> n && n != 0 )
{
for( i = 0 ; i < n ; i++ )
neighbor[ i ].clear() ;
fill( colorMap, colorMap + MaxN, -1 ) ;
cin >> m ;
for( i = 0 ; i < m ; i++ )
{
cin >> a >> b ;
neighbor[ a ].push_back( b ) ;
neighbor[ b ].push_back( a ) ;
}
solved = true ;
dfs( 0, 0 ) ;
if( solved == true )
cout << "BICOLORABLE." << endl ;
else
cout << "NOT BICOLORABLE." << endl ;
}
return 0 ;
}