Submission #503297

#TimeUsernameProblemLanguageResultExecution timeMemory
503297rainboyHiperkocka (COCI21_hiperkocka)C11
110 / 110
50 ms3808 KiB
#include <stdio.h>
#include <stdlib.h>

#define N	16

int *ej[N + 1], eo[N + 1];

void append(int i, int j) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
	ej[i][o] = j;
}

int bb[N + 1], h;

void dfs(int p, int i, int b) {
	int o;

	bb[i] = b;
	for (o = eo[i]; o--; ) {
		int j = ej[i][o];

		if (j != p)
			dfs(i, j, b | 1 << h++);
	}
}

int main() {
	static int kk[1 << N];
	int n, i, j, b;

	scanf("%d", &n);
	for (i = 0; i <= n; i++)
		ej[i] = (int *) malloc(2 * sizeof *ej[i]);
	for (h = 0; h < n; h++) {
		scanf("%d%d", &i, &j);
		append(i, j), append(j, i);
	}
	h = 0, dfs(-1, 0, 0);
	for (b = 1; b < 1 << n; b++)
		kk[b] = kk[b & b - 1] ^ 1;
	printf("%d\n", 1 << n - 1);
	for (b = 0; b < 1 << n; b++)
		if (kk[b] == 0) {
			for (i = 0; i <= n; i++)
				printf("%d ", b ^ bb[i]);
			printf("\n");
		}
	return 0;
}

Compilation message (stderr)

Main.c: In function 'append':
Main.c:11:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   11 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
Main.c: In function 'main':
Main.c:43:20: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   43 |   kk[b] = kk[b & b - 1] ^ 1;
      |                  ~~^~~
Main.c:44:24: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   44 |  printf("%d\n", 1 << n - 1);
      |                      ~~^~~
Main.c:34:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:38:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d%d", &i, &j);
      |   ^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...