#include "speedrun.h"
#include <cstdio>
#include <vector>
using namespace std;
int n, center;
vector<int> adj[1006];
bool visited[1006];
void assign(int x, int y, int z) {
for (int i = 0; i < 10; i++) setHint(x + 1, y * 10 + i + 1, z & 1 << i ? true : false);
}
int get(int y) {
int ret = 0;
for (int i = 0; i < 10; i++) ret |= getHint(y * 10 + i + 1) << i;
return ret;
}
void move(int x) {
visited[x] = true;
goTo(x + 1);
}
// void _dfs(int x, int prev = -1) {
// int pv = -1;
// for (auto &i: adj[x]) if (i != prev) {
// if (pv == -1) assign(x, 0, i);
// else assign(pv, 1, i);
// pv = i;
// _dfs(i, x);
// }
// if (pv == -1) assign(x, 0, 1023);
// else assign(pv, 1, x);
// }
void assignHints(int subtask, int n, int a[], int b[]) {
::n = n;
for (int i = 1; i < n; i++) {
adj[a[i] - 1].push_back(b[i] - 1);
adj[b[i] - 1].push_back(a[i] - 1);
}
setHintLen(20);
if (n == 1) return;
for (int i = 0; i < n; i++) if ((int)adj[i].size() != 1) center = i;
for (int i = 0; i < n; i++) assign(i, 0, center);
assign(center, 1, adj[center][0]);
for (int i = 0; i < (int)adj[center].size(); i++) assign(adj[center][i], 1, adj[center][(i + 1) % (int)adj[center].size()]);
// _dfs(0);
}
// void dfs(int x, int prev = -1) {
// visited[x] = true;
// int child = get(0);
// if (child != 1023 && !visited[child]) {
// goTo(child + 1);
// dfs(child);
// goTo(x + 1);
// }
// int nx = get(1);
// if (nx != 1023 && !visited[nx]) {
// goTo(nx + 1);
// dfs(nx);
// goTo(x + 1);
// }
// }
bool notVisited() {
for (int i = 0; i < n; i++) if (!visited[i]) return true;
return false;
}
void speedrun(int subtask, int n, int st) {
::n = n;
if (n == 1) return;
st--;
visited[st] = true;
while (notVisited()) {
int a = get(0), b = get(1);
if (visited[b]) move(a);
else move(a), move(b);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
104 ms |
672 KB |
Used too many wrong interactions |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
145 ms |
728 KB |
Output is correct |
2 |
Correct |
190 ms |
692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
118 ms |
704 KB |
Used too many wrong interactions |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
292 ms |
676 KB |
Used too many wrong interactions |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
80 ms |
672 KB |
Used too many wrong interactions |
2 |
Halted |
0 ms |
0 KB |
- |