#include <stdio.h>
#define N 1000000
int max(int a, int b) { return a > b ? a : b; }
int ll[N + 1], rr[N + 1], cc[N + 1], mx[N + 1];
void dfs(int i, int d) {
if (i <= 0)
mx[d] = max(mx[d], -i);
else
dfs(ll[i], d + 1), dfs(rr[i], d + 1);
}
void print(int a) {
if (a == 0)
return;
print(a / 2);
printf("%d", a % 2);
}
int main() {
int n, i, d, d_;
scanf("%d", &n);
for (i = 1; i <= n; i++)
scanf("%d%d", &ll[i], &rr[i]);
dfs(1, 0);
d_ = 0;
for (d = 1; d <= n; d++)
if ((d - d_ > 30 ? 0 : (mx[d_] >> d - d_)) < mx[d])
d_ = d;
if (mx[d_] == 0)
printf("0\n");
else {
print(mx[d_]);
while (d_--)
printf("0");
printf("\n");
}
return 0;
}
Compilation message
poklon.c: In function 'main':
poklon.c:32:39: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
32 | if ((d - d_ > 30 ? 0 : (mx[d_] >> d - d_)) < mx[d])
| ~~^~~~
poklon.c:26:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
poklon.c:28:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%d%d", &ll[i], &rr[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
3 ms |
332 KB |
Output is correct |
12 |
Correct |
4 ms |
396 KB |
Output is correct |
13 |
Correct |
14 ms |
1052 KB |
Output is correct |
14 |
Correct |
28 ms |
1768 KB |
Output is correct |
15 |
Correct |
26 ms |
1152 KB |
Output is correct |
16 |
Correct |
92 ms |
4588 KB |
Output is correct |
17 |
Correct |
219 ms |
10032 KB |
Output is correct |
18 |
Correct |
222 ms |
10720 KB |
Output is correct |
19 |
Correct |
283 ms |
10548 KB |
Output is correct |
20 |
Correct |
256 ms |
28600 KB |
Output is correct |