#include "speedrun.h"
#include <bits/stdc++.h>
using namespace std;
const int sz = 2005;
int cnt, num, in[sz], t[sz], p[sz];
vector<int> g[sz];
void dfs(int v)
{
in[v] = ++cnt;
t[in[v]] = v;
for(int i : g[v])
{
if(!in[i])
{
p[i] = v;
dfs(i);
}
}
}
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]);
}
setHintLen(20);
dfs(1);
for(int i = 1; i <= N; i++)
{
int nxt = t[in[i] + 1];
int prv = p[i];
int h = 0;
for(int j = 0; j < 10; j++)
{
if(prv & (1 << j)) setHint(i, (j + 11), 1);
if(nxt & (1 << j)) setHint(i, (j + 1), 1);
}
}
}
void f(int go, int N)
{
if(num == N)return;
int nxt = 0, prv = 0;
for(int i = 0; i < 10; i++)
{
nxt += getHint(i + 1) * (1 << i);
prv += getHint(i + 11) * (1 << i);
}
if(go)
{
if(!goTo(go))
{
// cout << "could not go to " << go << ", went to " << prv << endl;
goTo(prv);
f(go, N);
}
else
{
num++;
// cout << "went to " << go << endl;
f(0, N);
}
}
else
{
if(!goTo(nxt))
{
goTo(prv);
//cout << "could not go to " << nxt << ", went to " << prv << endl;
f(nxt, N);
}
else
{
//cout << "went to " << nxt << endl;
num++;
f(0, N);
}
}
}
void speedrun(int subtask, int N, int start)
{
num = 1;
f(0, N);
}
Compilation message
speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:37:13: warning: unused variable 'h' [-Wunused-variable]
37 | int h = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
904 KB |
Invalid node index to goTo |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
1932 KB |
Invalid node index to goTo |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
908 KB |
Invalid node index to goTo |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
59 ms |
1860 KB |
Invalid node index to goTo |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
47 ms |
1420 KB |
Invalid node index to goTo |
2 |
Halted |
0 ms |
0 KB |
- |