#include "speedrun.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> con[1005];
void pune_hint(int nod, int x, int y, int z)
{
for(int i=0;i<10;i++)
{
if(((1<<i)&x))
setHint(nod,i+1,1);
if(((1<<i)&y))
setHint(nod,i+11,1);
if(((1<<i)&z))
setHint(nod,i+21,1);
}
}
void dfs(int nod, int par, int tori)
{
vector<int> v;
for(int adj:con[nod])
if(adj!=par)
v.push_back(adj);
for(int i=0;i<v.size();i++)
{
if(i+1 < v.size())
dfs(v[i],nod,v[i+1]);
else
dfs(v[i],nod,0);
}
if(tori==0)
{
if(v.empty()) pune_hint(nod,par,0,par);
else pune_hint(nod,par,v[0],par);
}
else
{
if(v.empty()) pune_hint(nod,tori,0,par);
else pune_hint(nod,tori,v[0],par);
}
}
void assignHints(int subtask, int N, int A[], int B[])
{
setHintLen(30);
for(int i=1;i<N;i++)
{
con[A[i]].push_back(B[i]);
con[B[i]].push_back(A[i]);
}
dfs(1,0,0);
}
int get1()
{
int aux=0;
for(int i=0;i<10;i++)
if(getHint(i+1))
aux += (1<<i);
return aux;
}
int get2()
{
int aux=0;
for(int i=0;i<10;i++)
if(getHint(i+11))
aux += (1<<i);
return aux;
}
int get3()
{
int aux=0;
for(int i=0;i<10;i++)
if(getHint(i+21))
aux += (1<<i);
return aux;
}
int nxt[1005],down[1005],parent[1005];
void dfs_speedrun(int nod, int par)
{
nxt[nod] = get1();
down[nod] = get2();
parent[nod] = get3();
if(down[nod]==0)///e frunza
{
if(par!=0) assert(goTo(par));
return;
}
int c = down[nod];
while(1)
{
assert(goTo(c));
dfs_speedrun(c,nod);
c = nxt[c];
if(c==nod)
break;
}
if(par!=0) assert(goTo(par));
}
void speedrun(int subtask, int N, int start)
{
int cur=start;
while(cur!=1)
{
int p = get3();
assert(goTo(p));
cur=p;
}
assert(cur==1);
dfs_speedrun(1,0);
}
/**
5
1 2
2 3
3 4
3 5
4
*/
Compilation message
speedrun.cpp: In function 'void dfs(int, int, int)':
speedrun.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
speedrun.cpp:25:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | if(i+1 < v.size())
| ~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
872 KB |
Output is correct |
2 |
Correct |
75 ms |
1192 KB |
Output is correct |
3 |
Correct |
65 ms |
688 KB |
Output is correct |
4 |
Correct |
51 ms |
904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
The length is too large |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
The length is too large |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
880 KB |
Output is correct |
2 |
Correct |
68 ms |
868 KB |
Output is correct |
3 |
Correct |
56 ms |
1124 KB |
Output is correct |
4 |
Correct |
64 ms |
940 KB |
Output is correct |
5 |
Correct |
86 ms |
684 KB |
Output is correct |
6 |
Correct |
57 ms |
940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
65 ms |
1192 KB |
Partial solution |
2 |
Partially correct |
71 ms |
984 KB |
Partial solution |
3 |
Partially correct |
48 ms |
892 KB |
Partial solution |
4 |
Partially correct |
56 ms |
872 KB |
Partial solution |
5 |
Partially correct |
64 ms |
688 KB |
Partial solution |
6 |
Partially correct |
72 ms |
684 KB |
Partial solution |
7 |
Partially correct |
37 ms |
684 KB |
Partial solution |