#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define ld long double
#define ar array
const int INF = 1e17;
const int MOD = 1e9+7;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int N; cin >> N;
vector<ar<int,2>> adj(N);
for (auto &i : adj) {
cin >> i[0] >> i[1];
if (i[0] > 0) --i[0];
if (i[1] > 0) --i[1];
}
int ans = 0;
function<void(int, int)> dfs = [&](int u, int depth) {
int lc = adj[u][0], rc = adj[u][1];
if (lc < 0) ans = max(-lc * (1 << depth), ans);
else dfs(lc, depth + 1);
if (rc < 0) ans = max(-rc * (1 << depth), ans);
else dfs(rc, depth + 1);
};
dfs(0, 1);
vector<int> remdi;
while (ans) { remdi.push_back(ans & 1); ans >>= 1; }
reverse(remdi.begin(), remdi.end());
for (int i : remdi) cout << i;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
240 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
11 |
Incorrect |
4 ms |
972 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
872 KB |
Output isn't correct |
13 |
Incorrect |
15 ms |
3784 KB |
Output isn't correct |
14 |
Incorrect |
29 ms |
7508 KB |
Output isn't correct |
15 |
Incorrect |
28 ms |
3400 KB |
Output isn't correct |
16 |
Incorrect |
121 ms |
21072 KB |
Output isn't correct |
17 |
Incorrect |
236 ms |
46516 KB |
Output isn't correct |
18 |
Incorrect |
266 ms |
50104 KB |
Output isn't correct |
19 |
Incorrect |
295 ms |
47168 KB |
Output isn't correct |
20 |
Incorrect |
335 ms |
111564 KB |
Output isn't correct |