Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back to list of problems

Bicoloring

10004.c

#include <stdio.h>
#include <string.h>

int n,l;
int arr[205][205];
int col[205];

void
colorea(void) {
	int i,j;

	while (1) {
		int done = 1;
		for (i=0; i<n; i++) {
			if (col[i] == 0) {
				done=0;
			}
			if (col[i] != 0) {
				for (j=0; j<n; j++) {
					if (arr[i][j]) {
						if (!col[j]) {
							col[j] = (col[i] ^ 1);
						}
						if (col[j] != (col[i] ^ 1)) {
							printf("NOT BICOLORABLE.\n");
							return;
						}
					}
				}
			}
		}
		if (done) {
			printf("BICOLORABLE.\n");
			return;
		}
	}
}

int
main(void) {
	int a,b;
	int i;

	while (1) {
		scanf("%d %d", &n, &l);
		if (n==0) {
			return 0;
		}
		memset(arr, 0, sizeof(arr));
		memset(col, 0, sizeof(col));
		for (i=0; i<l; i++) {
			scanf("%d %d", &a, &b);
			arr[a][b] = arr[b][a] = 1;
		}
		col[0] = 2;
		colorea();
	}
}