#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]; long long sum;
void dfs(int i, int d) {
if (i <= 0) {
sum += -i;
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 ((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:33:20: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
33 | if ((mx[d_] >> d - d_) < mx[d])
| ~~^~~~
poklon.c:27:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
poklon.c:29:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d%d", &ll[i], &rr[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 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 |
0 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 |
332 KB |
Output is correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
4 ms |
588 KB |
Output is correct |
13 |
Correct |
14 ms |
2252 KB |
Output is correct |
14 |
Correct |
28 ms |
4472 KB |
Output is correct |
15 |
Correct |
26 ms |
2700 KB |
Output is correct |
16 |
Correct |
93 ms |
12676 KB |
Output is correct |
17 |
Correct |
216 ms |
28292 KB |
Output is correct |
18 |
Correct |
222 ms |
30188 KB |
Output is correct |
19 |
Correct |
270 ms |
30868 KB |
Output is correct |
20 |
Correct |
295 ms |
77256 KB |
Output is correct |