#include "speedrun.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<vector<int>> adj(1e3+1);
vector<int> p(1e3+1,0);
void dfs(int u, int P) {
for (auto v:adj[u]) {
if (v==P) continue;
p[v]=u;
dfs(v,u);
}
}
vector<pair<int,int>> toadd;
vector<pair<int,int>> edgeto(1e3+1);
void dfs2(int u, int P) {
int cnt=0;
for (auto v:adj[u]) {
if (v==P) continue;
if (cnt==0) {
for (int j=10; j; --j) {
setHint(u,j+10,!!(v&(1<<(j-1))));
}
edgeto[u]={u,v};
++cnt;
} else {
toadd.push_back({u,v});
}
}
if (cnt==0) {
//cout<<u<<' '<<P<<": ";
//for (auto x:toadd) cout<<x.first<<' '<<x.second<<" ";
//cout<<'\n';
if (toadd.size()==0) return;
auto k=toadd.back(); toadd.pop_back();
for (int j=10; j; --j) {
setHint(u,j+10,!!(k.second&(1<<(j-1))));
}
edgeto[u]={k.first,k.second};
}
dfs2(edgeto[u].second,edgeto[u].first);
}
void assignHints(int id,int n, int a[], int b[]) {
if (id==2) {
setHintLen(20);
vector<int>deg(n+1,0);
for(int i=0;i<n-1;++i) deg[a[i]]++;
for(int i=0;i<n-1;++i) deg[b[i]]++;
int mx=0;
for(int i=1;i<=n;++i) if (deg[i]>deg[mx]) mx=i;
for (int i=1; i<=n; ++i) {
if (i==mx) setHint(i,20,1);
for (int j=11; j>0; --j) {
setHint(i,j,!!(mx&(1<<(j-1))));
}
}
return;
}
if (id==3) {
setHintLen(20);
vector<pair<int,int>> adj(n+1,{0,0});
for (int i=1; i<n; ++i) {
if (adj[a[i]].first) adj[a[i]].second=b[i];
else adj[a[i]].first=b[i];
if (adj[b[i]].first) adj[b[i]].second=a[i];
else adj[b[i]].first=a[i];
}
for (int i=1; i<=n; ++i) {
for (int j=10; j; --j) {
setHint(i,j,!!(adj[i].first&(1<<(j-1))));
}
for (int j=10; j; --j) {
setHint(i,j+10,!!(adj[i].second&(1<<(j-1))));
}
}
return;
}
for (int i=1; i<n; ++i) {
adj[a[i]].push_back(b[i]);
adj[b[i]].push_back(a[i]);
}
dfs(1,0);
setHintLen(20);
for (int i=1; i<=n; ++i) {
for (int j=10; j; --j) {
setHint(i,j,!!(p[i]&(1<<(j-1))));
}
}
dfs2(1,0);
}
vector<int> par(1e3+1,0);
int n;
void climb(int u, int need) {
int p=0;
for (int j=10; j; --j) p+=getHint(j)<<(j-1);
if (p==need) return;
par[u]=p;
goTo(p);
climb(u,need);
}
void visit(int u) {
int y=0;
int p=0;
for (int j=10; j; --j) p+=getHint(j)<<(j-1);
par[u]=p;
for (int j=10; j; --j) y+=getHint(j+10)<<(j-1);
//cout<<u<<' '<<par[u]<<' '<<y<<'\n';
//int k; cin>>k;
//if (k==-1) exit(0);
if (y==0) return;
bool b=goTo(y);
if (b==1) {
visit(y);
} else {
do {
goTo(par[u]);
u=par[u];
b=goTo(y);
} while (b==0);
visit(y);
}
}
int center=0;
vector<vector<int>> adj2(1e3+1,vector<int>(1e3+1,0));
void dfs22(int u, int p) {
int l=0, r=0;
for (int j=10; j>0; --j) {
l+=getHint(j)<<(j-1);
r+=getHint(j+10)<<(j-1);
}
adj2[u][l]=1, adj2[u][r]=1;
for (int i=1; i<=n; ++i) {
if (i==p) continue;
if (adj2[u][i]) {
goTo(i);
dfs22(i,u);
}
}
if (p==-1) return;
goTo(p);
}
void speedrun(int id,int N,int start) {
n=N;
if (id==2) {
for (int j=11; j>0; --j) {
center+=getHint(j)<<(j-1);
}
bool b=getHint(20);
if (!b) {
goTo(center);
}
for (int i=1; i<=n; ++i) {
if (i==center) continue;
goTo(i);
goTo(center);
}
return;
}
if (id==3) {
dfs22(start,-1);
return;
}
climb(start,0);
visit(1);
}
Compilation message
In file included from /usr/include/c++/10/bits/move.h:57,
from /usr/include/c++/10/bits/stl_pair.h:59,
from /usr/include/c++/10/bits/stl_algobase.h:64,
from /usr/include/c++/10/bits/specfun.h:45,
from /usr/include/c++/10/cmath:1927,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
from speedrun.cpp:2:
/usr/include/c++/10/type_traits: In substitution of 'template<class _Fn, class ... _Args> using invoke_result_t = typename std::invoke_result::type [with _Fn = int; _Args = {}]':
/usr/include/c++/10/variant:1705:13: required from 'constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = int; _Variants = {}]'
speedrun.cpp:174:16: required from here
/usr/include/c++/10/type_traits:2957:11: error: no type named 'type' in 'struct std::invoke_result<int>'
2957 | using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
| ^~~~~~~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:133,
from speedrun.cpp:2:
/usr/include/c++/10/variant: In instantiation of 'constexpr decltype(auto) std::visit(_Visitor&&, _Variants&& ...) [with _Visitor = int; _Variants = {}]':
speedrun.cpp:174:16: required from here
/usr/include/c++/10/variant:1708:13: error: no type named 'type' in 'struct std::invoke_result<int>'
1708 | using _Tag = __detail::__variant::__deduce_visit_result<_Result_type>;
| ^~~~