#include "speedrun.h"
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
vector <int> g[1005];
int dfn[1005],par[1005],clk;
void dfs0(int u,int fa)
{
dfn[u]=++clk,par[u]=fa;
for(int i=0;i<g[u].size();i++) if(g[u][i]!=fa) dfs0(g[u][i],u);
}
void assignHints(int subtask, int N, int A[], int B[])
{
setHintLen(20);
// return;
for(int i=1;i<N;i++) g[A[i]].pb(B[i]),g[B[i]].pb(A[i]);
dfs0(1,0);
for(int i=1;i<=N;i++)
{
for(int j=0;j<10;j++) setHint(i,j+1,((par[i]&(1<<j))?1:0));
int nxt=0;
for(int j=1;j<=N;j++) if(dfn[j]==dfn[i]+1) nxt=j;
for(int j=0;j<10;j++) setHint(i,j+11,((nxt&(1<<j))?1:0));
}
}
int getpar()
{
int res=0;
for(int j=0;j<10;j++) if(getHint(j+1)) res+=(1<<j);
return res;
}
int getnxt()
{
int res=0;
for(int j=0;j<10;j++) if(getHint(j+11)) res+=(1<<j);
return res;
}
int vis[1005];
void speedrun(int subtask, int N, int start)
{
int L=getLength();
int u=start;
vis[u]=1;
int cnt=1;
while(getpar()) u=getpar(),vis[u]=1,cnt++,goTo(u);
int v=-1;
while(cnt<N)
{
if(v==-1) v=getnxt();
// cout<<u<<" "<<v<<"\n";
// system("pause");
if(goTo(v)) u=v,cnt+=(vis[u]^1),vis[u]=1,v=getnxt();
else u=getpar(),goTo(u);
}
}
Compilation message
speedrun.cpp: In function 'void dfs0(int, int)':
speedrun.cpp:13:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int i=0;i<g[u].size();i++) if(g[u][i]!=fa) dfs0(g[u][i],u);
| ~^~~~~~~~~~~~
speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:44:6: warning: unused variable 'L' [-Wunused-variable]
44 | int L=getLength();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
1524 KB |
Output is correct |
2 |
Correct |
105 ms |
1876 KB |
Output is correct |
3 |
Correct |
100 ms |
1528 KB |
Output is correct |
4 |
Correct |
117 ms |
1368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
1368 KB |
Output is correct |
2 |
Correct |
104 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
93 ms |
1100 KB |
Output is correct |
2 |
Correct |
106 ms |
1556 KB |
Output is correct |
3 |
Correct |
99 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
1368 KB |
Output is correct |
2 |
Correct |
98 ms |
1120 KB |
Output is correct |
3 |
Correct |
102 ms |
1608 KB |
Output is correct |
4 |
Correct |
89 ms |
1624 KB |
Output is correct |
5 |
Correct |
107 ms |
1376 KB |
Output is correct |
6 |
Correct |
93 ms |
1268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
1360 KB |
Output is correct |
2 |
Correct |
95 ms |
1276 KB |
Output is correct |
3 |
Correct |
102 ms |
1636 KB |
Output is correct |
4 |
Correct |
105 ms |
1100 KB |
Output is correct |
5 |
Correct |
93 ms |
1536 KB |
Output is correct |
6 |
Correct |
105 ms |
1824 KB |
Output is correct |
7 |
Correct |
102 ms |
1620 KB |
Output is correct |