#include "speedrun.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 2002;
int par[N], idx[N];
vector<int> g[N], order;
void dfs(int x, int fa) {
par[x] = fa;
idx[x] = (int) order.size();
order.push_back(x);
for (int y : g[x]) if (y != fa) dfs(y, x);
}
void assignHints(int subtask, int n, int a[], int b[]) {
for (int i = 1; i < n; i++) {
g[a[i]].push_back(b[i]);
g[b[i]].push_back(a[i]);
}
dfs(1, 0);
setHintLen(20);
// printf("-- %d\n", order[idx[1] + 1]);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 10; j++) setHint(i, j + 1, par[i] >> j & 1);
if (idx[i] + 1 < n) for (int j = 0; j < 10; j++) setHint(i, 11 + j, order[idx[i] + 1] >> j & 1);
else for (int j = 0; j < 10; j++) setHint(i, 11 + j, order[idx[i] + 1] >> j & 1);
}
}
int getPar() {
int x = 0;
for (int i = 0; i < 10; i++) if (getHint(i + 1)) x += (1 << i);
return x;
}
int getChild() {
int x = 0;
for (int i = 0; i < 10; i++) if (getHint(i + 11)) x += (1 << i);
return x;
}
vector<int> stk;
void go(int x, int fa) {
int ch = getChild();
if (ch != 0) stk.push_back(ch);
// printf("trcim iz %d kid=%d\n", x, ch);
while (!stk.empty()) {
int y = stk.back();
if (goTo(y)) {
stk.pop_back();
go(y, x);
goTo(x);
} else break;
}
}
void speedrun(int subtask, int N, int start) {
while (getPar() != 0) {
int nxt = getPar();
goTo(nxt);
start = nxt;
}
go(start, start);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
183 ms |
772 KB |
Output is correct |
2 |
Correct |
151 ms |
944 KB |
Output is correct |
3 |
Correct |
234 ms |
740 KB |
Output is correct |
4 |
Correct |
213 ms |
728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
736 KB |
Output is correct |
2 |
Correct |
169 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
800 KB |
Output is correct |
2 |
Correct |
177 ms |
812 KB |
Output is correct |
3 |
Correct |
192 ms |
792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
194 ms |
800 KB |
Output is correct |
2 |
Correct |
115 ms |
696 KB |
Output is correct |
3 |
Correct |
205 ms |
736 KB |
Output is correct |
4 |
Correct |
193 ms |
892 KB |
Output is correct |
5 |
Correct |
213 ms |
728 KB |
Output is correct |
6 |
Correct |
230 ms |
720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
201 ms |
740 KB |
Output is correct |
2 |
Correct |
227 ms |
780 KB |
Output is correct |
3 |
Correct |
211 ms |
708 KB |
Output is correct |
4 |
Correct |
201 ms |
932 KB |
Output is correct |
5 |
Correct |
176 ms |
704 KB |
Output is correct |
6 |
Correct |
232 ms |
736 KB |
Output is correct |
7 |
Correct |
186 ms |
704 KB |
Output is correct |