#include <bits/stdc++.h>
#include "speedrun.h"
using namespace std;
using vi = vector <int>;
void assignHints (int subtask, int n, int u[], int v[]) {
if (subtask==1){setHintLen(n);
for (int i = 1; i <= n-1; i++) {
setHint(u[i], v[i], true);
setHint(v[i], u[i], true);
}
return;
}
if (subtask==2) {
setHintLen(20);
int freq[n+1]{};
for (int i=1; i <= n-1; i++) {
freq[u[i]]++;
freq[v[i]]++;
}
int uu = max_element(freq, freq+n+1)-freq;
for (int i=1; i <= n; i++) {
for (int bit=0; bit < 20; bit++) {
setHint(i, bit+1, uu>>bit&1);
}
}
return;}
bool vis[n+5]{};
int freq[n+1]{};
vi adj[n+5];
for (int i = 1; i <= n-1; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
for (int i=1; i <= n-1; i++) {
freq[u[i]]++;
freq[v[i]]++;
}
int uu = min_element(freq+1, freq+n+1)-freq;
vis[uu]=true;
while (true) {
int v=-16;
for (int vv : adj[uu]) {
if (vis[vv]) continue;
vis[vv]=true;
v = vv;
break;
}
if (v==-16) {
for (int bit=0; bit < 20; bit++) {
setHint(uu, bit+1, uu>>bit&1);
}
break;
}
for (int bit=0; bit < 20; bit++) {
setHint(uu, bit+1, v>>bit&1);
}
uu=v;
}
}
const static void dfs1 (int u, int par, int n) {
for (int v = 1; v <= n; v++) {
if (v == u) continue;
if (v == par) continue;
if (getHint(v)) {
goTo(v);
dfs1(v, u, n);
goTo(u);
}
}
return;
};
void speedrun (int subtask, int n, int at) {
if (subtask==1) {dfs1(at, at, n); return;}
if (subtask==2) {int root=0;
for (int bit=0; bit < 20; bit++) {
root |= getHint(bit+1)<<bit;
}
goTo(root);
for (int u=1; u <= n; u++) {
if (u==root)continue;
goTo(u);
goTo(root);
}
return;}
bool vis[n+5]{};
int to=0;
while (true) {
vis[at]=true;
to=0;
for (int bit=0; bit < 20; bit++) {
to |= getHint(bit+1)>>bit;
}
if (!vis[to]) {
goTo(to);
at=to;
to=0;
continue;
}
bool die=true;
for (int i = 1; i <= n; i++) {
if (vis[i]) continue;
if (!goTo(i)) continue;
at=i;
die=false;
break;
}
if (die) break;
}
return;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
1692 KB |
Output is correct |
2 |
Correct |
21 ms |
1552 KB |
Output is correct |
3 |
Correct |
23 ms |
1464 KB |
Output is correct |
4 |
Correct |
22 ms |
1616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
1352 KB |
Output is correct |
2 |
Correct |
91 ms |
1336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
You must call setLength before you set anything |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
You must call setLength before you set anything |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
You must call setLength before you set anything |
2 |
Halted |
0 ms |
0 KB |
- |