ACM 2009. 6. 2. 20:49
반응형
I got accept from Judge Server

----------------------------------------------------------------------------------------------
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
79
80
81
82
83
84
85
86
87
88
#include <stdio.h>
 
#define MAXV   200
#define NOCOLOR   0
#define BLACK   1
#define RED    2
#define CONNECTED  1
#define DISCONNECTED 0
 
typedef struct
{
 int edges[MAXV][MAXV];
 int color[MAXV];
 int nvertices;     
 int nedges;     
}Graph;
 
int  checkBicoloring(int init);
int  checkBicoloring(int init, int color);
void initEdge();
 
Graph graph;
 
int main(void)
{
 int i, first=0, second=0, checkBicolor=0;
 
 while(1){
  scanf("%d", &graph.nvertices);
  if(graph.nvertices == 0)
   break;
  
  if(graph.nvertices < 1 || graph.nvertices > MAXV)
   continue;
 
  scanf("%d", &graph.nedges);
 
  initEdge();
 
  for(i=0; i<graph.nedges; i++){
   scanf("%d %d", &first, &second);
   graph.edges[first][second] = CONNECTED;
   graph.edges[second][first] = CONNECTED;
  }
 
  if(checkBicoloring(0, BLACK) == 0){
   printf("BICOLORABLE.\n");
  } 
  else{
   printf("NOT BICOLORABLE.\n");
  }
 } 
 return 0;
}
 
void initEdge()
{
 int i, j;
 for(i=0; i<MAXV; i++){
  graph.color[i] = NOCOLOR;
  for(j=0; j<MAXV; j++){
   graph.edges[i][j] = DISCONNECTED;
  }
 }
}
 
int checkBicoloring(int init, int color)
{
 int i;
 if (graph.color[init] == NOCOLOR)
  graph.color[init] = color;
 
 for (i=0; i<graph.nvertices; i++){
  if (graph.edges[init][i] == CONNECTED){
   if(graph.color[init] == graph.color[i]){
    return 1;
   }
 
   if(graph.color[i] == NOCOLOR){ 
    if(graph.color[init] == BLACK)
     return checkBicoloring(i, RED);
    else
     return checkBicoloring(i, BLACK);
   } 
  }
 }
 return 0;
}


반응형

'ACM' 카테고리의 다른 글

[Accept] 10099 - The Tourist Guide  (0) 2009.06.02
[Time Limit] 10099 - The Tourist Guide  (0) 2009.06.02
[Accept] 100 - The 3n+1 problem  (0) 2009.06.02
10006 - Carmichael Numbers  (0) 2009.06.02
850 - Crypt Kicker II  (0) 2009.06.02
posted by ssuk1010
: