#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
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 time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
280 KB |
Output is correct |
5 |
Correct |
1 ms |
276 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
280 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
42 ms |
3808 KB |
Output is correct |
10 |
Correct |
5 ms |
588 KB |
Output is correct |
11 |
Correct |
10 ms |
972 KB |
Output is correct |
12 |
Correct |
40 ms |
3776 KB |
Output is correct |
13 |
Correct |
1 ms |
284 KB |
Output is correct |
14 |
Correct |
40 ms |
3724 KB |
Output is correct |
15 |
Correct |
19 ms |
1860 KB |
Output is correct |
16 |
Correct |
11 ms |
964 KB |
Output is correct |
17 |
Correct |
40 ms |
3696 KB |
Output is correct |
18 |
Correct |
40 ms |
3724 KB |
Output is correct |
19 |
Correct |
43 ms |
3688 KB |
Output is correct |
20 |
Correct |
39 ms |
3788 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
40 ms |
3724 KB |
Output is correct |
23 |
Correct |
50 ms |
3716 KB |
Output is correct |
24 |
Correct |
39 ms |
3688 KB |
Output is correct |
25 |
Correct |
41 ms |
3756 KB |
Output is correct |
26 |
Correct |
21 ms |
1884 KB |
Output is correct |