This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "speedrun.h"
#include <bits/stdc++.h>
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;
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,!!(u&(1<<(j-1))));
setHint(u,j+20,!!(v&(1<<(j-1))));
}
++cnt;
} else {
toadd.push_back({u,v});
}
}
for (auto v:adj[u]) {
if (v==P) continue;
dfs2(v,u);
}
if (cnt==0) {
if (toadd.size()==0) return;
auto k=toadd.back(); toadd.pop_back();
for (int j=10; j; --j) {
setHint(u,j+10,!!(k.first&(1<<(j-1))));
setHint(u,j+20,!!(k.second&(1<<(j-1))));
}
}
}
void assignHints(int id,int n, int a[], int b[]) {
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(30);
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 x=0, 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) x+=getHint(j+10)<<(j-1);
for (int j=10; j; --j) y+=getHint(j+20)<<(j-1);
par[y]=x;
//cout<<u<<' '<<par[u]<<' '<<x<<' '<<y<<'\n';
//int k; cin>>k;
//if (k==-1) exit(0);
if (x==y && y==0) return;
if (u!=x) climb(u,par[x]);
goTo(y);
visit(y);
}
void speedrun(int id,int N,int start) {
n=N;
climb(start,0);
visit(1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |