#include <bits/stdc++.h>
#include "speedrun.h"
using namespace std;
const int m = 31;
vector <int> conv (int x) {
vector <int> ret;
for (int i = 9; i >= 0; i--) {
ret.push_back((x >> i) & 1);
}
}
void assignHints (int subtask, int n, int a[], int b[]) {
if (subtask == 3) {
vector <int> adj[n + 1];
for (int i = 1; i < n; i++) {
adj[a[i]].push_back(b[i]);
adj[b[i]].push_back(a[i]);
}
setHintLen(20);
for (int i = 1; i <= n; i++) {
auto d = conv(adj[i][0]);
for (int l = 1; l <= 10; l++) {
setHint(i, l, d[l - 1]);
}
if (adj[i].size() == 1) continue;
d = conv(adj[i][1]);
for (int l = 1; l <= 10; l++) {
setHint(i, l + 10, d[l - 1]);
}
}
return;
}
if (subtask == 2) {
int deg[n + 1] = {};
if (n == 1) return;
for (int i = 1; i < n; i++) {
deg[a[i]]++;
deg[b[i]]++;
}
int pos = 1;
for (int i = 1; i <= n; i++) {
if (deg[i] > 1) {
pos = i;
}
}
setHintLen(1);
setHint(pos, 1, 1);
return;
}
vector <int> adj[n + 1];
for (int i = 1; i < n; i++) {
adj[a[i]].push_back(b[i]);
adj[b[i]].push_back(a[i]);
}
setHintLen(316);
for (int i = 1; i <= n; i++) {
if (adj[i].size() > m) continue;
setHint(i, 316, 1);
for (int j = 0; j < (int)adj[i].size(); j++) {
auto x = conv(adj[i][j]);
for (int l = 10 * j + 1; l <= 10 * j + 10; l++) {
setHint(i, l, x[l - 10 * j + 1]);
}
}
}
}
int n;
void dfs (int pos, int par) {
if (getHint(316) == 1) {
vector <int> adj;
for (int j = 0; j <= 30; j++) {
int x = 0;
for (int l = 10 * j + 1; l <= 10 * j + 10; l++) {
x *= 2; x += getHint(l);
}
if (x != 0 && x != par) {
adj.push_back(x);
}
}
for (auto i : adj) {
goTo(i);
dfs(i, pos);
goTo(pos);
}
return;
}
for (int i = 1; i <= n; i++) {
if (i == pos || i == par) continue;
if (goTo(i)) {
dfs(i, pos);
goTo(pos);
}
}
}
void dfs2 (int pos, int par) {
int x = 0;
for (int i = 1; i <= 10; i++) {
x *= 2; x += getHint(i);
}
if (x != 0 && x != par) {
goTo(x); dfs2(x, pos); goTo(pos);
}
x = 0;
for (int i = 11; i <= 20; i++) {
x *= 2; x += getHint(i);
}
if (x != 0 && x != par) {
goTo(x); dfs2(x, pos); goTo(pos);
}
}
void speedrun (int subtask, int N, int start) {
if (subtask == 3) {
dfs2(start, -1);
return;
}
if (subtask == 2) {
n = N;
if (n == 1) return;
int x = getHint(1);
if (x == 1) {
for (int i = 1; i <= n; i++) {
if (i == start) continue;
goTo(i); goTo(start);
}
return;
}
for (int i = 1; i <= n; i++) {
if (i == start) continue;
if (goTo(i)) {
for (int j = 1; j <= n; j++) {
if (j == i || j == start) continue;
goTo(j); goTo(i);
}
goTo(start);
return;
}
}
}
n = N; dfs(start, -1);
}
Compilation message
speedrun.cpp: In function 'std::vector<int> conv(int)':
speedrun.cpp:10:1: warning: no return statement in function returning non-void [-Wreturn-type]
10 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
532 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1280 KB |
Output is correct |
2 |
Correct |
9 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
536 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
536 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
The length is too large |
2 |
Halted |
0 ms |
0 KB |
- |