This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
else if (subtask == 3){
setHintLen(20);
vector<bool> isSet(N + 1, 0);
for (int i = 1; i < N; i++){
int x = A[i], y = B[i];
if (!isSet[x]){
for (int k = 0; k <= 9; k++)
if (y & (1 << k))
setHint(x, k + 1, 1);
isSet[x] = 1;
}
else {
for (int k = 0; k <= 9; k++)
if (y & (1 << k))
setHint(x, k + 11, 1);
}
if (!isSet[y]){
for (int k = 0; k <= 9; k++)
if (x & (1 << k))
setHint(y, k + 1, 1);
isSet[y] = 1;
}
else {
for (int k = 0; k <= 9; k++)
if (x & (1 << k))
setHint(y, k + 11, 1);
}
}
}
}
void dfs1(int curr, int par, int N){
for (int i = 1; i <= N; i++){
if (!getHint(i)) continue;
if (i == par) continue;
goTo(i);
dfs1(i, curr, N);
}
if (par != -1) goTo(par);
}
void dfs2(int curr, int par){
int c1 = 0, c2 = 0;
for (int k = 0; k <= 9; k++)
if (getHint(k + 1))
c1 += (1 << k);
for (int k = 0; k <= 9; k++)
if (getHint(k + 11))
c2 += (1 << k);
if (c1 != par){
goTo(c1);
dfs2(c1, curr);
}
if (c2 != par){
goTo(c2);
dfs2(c2, curr);
}
if (par != -1) goTo(par);
}
void speedrun(int subtask, int N, int start) {
if (subtask == 1) dfs1(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);
}
}
else if (subtask == 3) dfs2(start, -1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |