Follows 10004.c (Total 61 lines):

/* @JUDGE_ID:4461XX 10004 C */
/* A */
#include<stdio.h>
#define N 200
char map[N][N] ;
void initial_map( int point )
{
	int i , j ;
	for( i=0 ; i<point ; i++ )
		for( j=i ; j<point ; j++ ) map[j][i] = map[i][j] = 0 ;
}
void make_map( int edge )
{
	int m , n ;
	for( ; edge ; edge-- ){
		scanf( "%d %d" , &m , &n ) ;
		map[m][n] = map[n][m] = 1 ;
	}
}
int CanSuit( int point )
{
	/* bfs */
	int used[N] , checked[N] , queue[N] , color[N] ;
	 /* used means if point i has been in the queue[] */
	 /* checked means if point i has been dealed out */
	 /* in color[] 0->noncolored 1->one -1->another */
	int i , tail , head ;
	for( i=0 ; i<point ; i++ ) color[i] = checked[i] = used[i] = 0 ;
	/* initialize checked[] and color[] and used[] */
	color[0] = 1 ;
	queue[0] = 0 ;
	used[0] = 1 ;
	tail = head = 0 ;
	for( ; head<=tail ; head++ ){
		for( i=0 ; i<point ; i++ )
			if( map[i][queue[head]] && !checked[i] ){
				if( !used[i] ){
					queue[++tail] = i ;
					used[i] = 1 ;
				}
				if( !color[i] ) color[i] = -color[queue[head]] ;
				else
					if( color[i] == color[queue[head]] ) return 0 ;
			}
		checked[queue[head]] = 1 ;
	}
	return 1 ;
}
void main( void )
{
	int point , edge ;
	while( scanf( "%d" , &point ) == 1 ){
		if( !point ) break ;
		initial_map( point ) ;
		scanf( "%d" , &edge ) ;
		make_map( edge ) ;
		if( CanSuit( point ) ) puts( "BICOLORABLE." ) ;
		else puts( "NOT BICOLORABLE." ) ;
	}
}
/* @END_OF_SOURCE_CODE */

Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com