#include "speedrun.h"
#include <vector>
using namespace std;
void assignHints(int subtask, int N, int A[], int B[]) {
if (subtask == 1){
setHintLen(N);
for (int i = 1; i < N; i++){
setHint(A[i], B[i], 1);
setHint(B[i], A[i], 1);
}
}
else if (subtask == 2){
setHintLen(20);
vector<int> occur(N + 1, 0);
for (int i = 1; i < N; i++){
occur[A[i]]++;
occur[B[i]]++;
}
int centre = 1; // when N is 2
for (int i = 1; i <= N; i++)
if (occur[i] > 1){
centre = i;
break;
}
for (int k = 0; k <= 19; k++)
if (centre & (1 << k))
for (int i = 1; i <= N; i++)
setHint(i, k + 1, 1);
}
}
void dfs(int curr, int par, int N){
for (int i = 1; i <= N; i++){
if (!getHint(i)) continue;
if (i == par) continue;
goTo(i);
dfs(i, curr, N);
}
if (par != -1) goTo(par);
}
void speedrun(int subtask, int N, int start) {
if (subtask == 1) dfs(start, -1, N);
else if (subtask == 2){
int centre = 0;
for (int i = 0; i <= 19; i++)
if (getHint(i + 1))
centre += (1 << i);
if (start != centre) goTo(centre);
for (int i = 1; i <= N; i++)
if (i != centre){
goTo(i);
goTo(centre);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
40 ms |
620 KB |
Output is correct |
2 |
Correct |
35 ms |
672 KB |
Output is correct |
3 |
Correct |
44 ms |
572 KB |
Output is correct |
4 |
Correct |
55 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
684 KB |
Output is correct |
2 |
Correct |
38 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
208 KB |
setHintLen was never called |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
setHintLen was never called |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
208 KB |
setHintLen was never called |
2 |
Halted |
0 ms |
0 KB |
- |