#include "speedrun.h"
#include <cstdio>
#include <vector>
using namespace std;
int n;
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 _dfs(int x, int prev = -1) {
if (prev == -1) assign(x, 2, 1023);
else assign(x, 2, prev);
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(30);
assign(0, 1, 1023);
_dfs(0);
}
void connect(int x, int y) {
adj[x].push_back(y);
adj[y].push_back(x);
}
void dfs(int x, int prev = -1) {
visited[x] = true;
if (get(0) != 1023) connect(x, get(0));
if (get(2) != 1023 && get(1) != 1023) connect(get(1), get(2));
for (int i = 0; i < (int)adj[x].size(); i++) if (adj[x][i] != prev && !visited[adj[x][i]]) {
goTo(adj[x][i] + 1);
dfs(adj[x][i], x);
goTo(x + 1);
}
}
void speedrun(int subtask, int n, int st) {
::n = n;
dfs(st - 1);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
210 ms |
740 KB |
Solution didn't visit every node |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
The length is too large |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
336 KB |
The length is too large |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
276 ms |
672 KB |
Solution didn't visit every node |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
291 ms |
784 KB |
Solution didn't visit every node |
2 |
Halted |
0 ms |
0 KB |
- |