#include <stdio.h>
#include <stdlib.h>
#define N 100
#define M (N * 4)
int max(int a, int b) { return a > b ? a : b; }
int *ej[N], eo[N];
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 pp[N];
void dfs(int p, int i) {
int o;
pp[i] = p;
for (o = eo[i]; o--; ) {
int j = ej[i][o];
if (j != p)
dfs(i, j);
}
}
int main() {
static int iii[2][N][M + 1], mm[2][N];
int n, m, h, i, j, t, l, d;
scanf("%d", &n);
if (n != 100)
return 0;
for (i = 0; i < n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
for (h = 0; h < n - 1; h++) {
scanf("%d%d", &i, &j);
append(i, j), append(j, i);
}
dfs(-1, 0);
m = 0;
for (t = 0; t < 2; t++) {
for (i = 0; i < n; i++) {
mm[t][i] = 0, iii[t][i][mm[t][i]] = j = i, l = 0;
for (l = 0, d = 1; j != 0; l++, d *= 3)
if (l % 2 == t)
for (h = 0; h < d && j != 0; h++)
iii[t][i][++mm[t][i]] = j = pp[j];
else
for (h = 0; h < d; h++)
iii[t][i][++mm[t][i]] = j;
m = max(m, mm[t][i]);
}
}
printf("%d\n", m * 2);
for (t = 0; t < 2; t++)
for (i = 0; i < n; i++)
for (h = 1; h <= m * 2; h++)
printf("%d%c", iii[t][i][(h + 1 - t) / 2], h < m * 2 ? ' ' : '\n');
return 0;
}
Compilation message
Main.c: In function 'append':
Main.c:14:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
14 | if (o >= 2 && (o & o - 1) == 0)
| ~~^~~
Main.c: In function 'main':
Main.c:37:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
Main.c:43:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d%d", &i, &j);
| ^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
4 ms |
856 KB |
Partially correct |
2 |
Partially correct |
4 ms |
860 KB |
Partially correct |
3 |
Partially correct |
4 ms |
860 KB |
Partially correct |
4 |
Partially correct |
5 ms |
860 KB |
Partially correct |
5 |
Partially correct |
4 ms |
860 KB |
Partially correct |
6 |
Partially correct |
4 ms |
860 KB |
Partially correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
604 KB |
Output is correct |
10 |
Correct |
0 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
604 KB |
Output is correct |
12 |
Correct |
0 ms |
604 KB |
Output is correct |
13 |
Correct |
0 ms |
604 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
604 KB |
Output is correct |
16 |
Partially correct |
1 ms |
604 KB |
Partially correct |
17 |
Partially correct |
1 ms |
772 KB |
Partially correct |
18 |
Partially correct |
1 ms |
604 KB |
Partially correct |
19 |
Partially correct |
1 ms |
604 KB |
Partially correct |
20 |
Partially correct |
2 ms |
604 KB |
Partially correct |
21 |
Partially correct |
1 ms |
604 KB |
Partially correct |
22 |
Partially correct |
2 ms |
604 KB |
Partially correct |
23 |
Partially correct |
2 ms |
604 KB |
Partially correct |
24 |
Partially correct |
3 ms |
860 KB |
Partially correct |
25 |
Partially correct |
4 ms |
860 KB |
Partially correct |