Back to list of problems
The House Of Santa Claus
291.c
/* 291 - The House Of Santa Claus */ #include <stdio.h> #include <string.h> typedef struct { int a; int b; } edge; #define NUM_EDGES 8 edge edges[NUM_EDGES] = {{1,2}, {1,3}, {1,5}, {2,3}, {2,5}, {3,4}, {3,5}, {4,5}}; int visited[NUM_EDGES]; int order[9]; void recorre(int n, int o) { int i; order[o] = n; if (o==8) { for (i=0; i<9; i++) { printf("%d", order[i]); } printf("\n"); return; } for (i=0; i<NUM_EDGES; i++) { if (!visited[i]) { if (edges[i].a==n) { visited[i] = 1; recorre(edges[i].b, o+1); visited[i] = 0; } else if (edges[i].b==n) { visited[i] = 1; recorre(edges[i].a, o+1); visited[i] = 0; } } } } int main(void) { memset(visited, 0, sizeof(visited)); recorre(1,0); return 0; }