#include <bits/stdc++.h>
#include "speedrun.h"
using namespace std;
vector<vector<int>> adj;
int visited[1005],parent[1005],nxt[1005],n,ult_nod=1;
void hint(int nod){
int poz=1;
while(parent[nod]>0){
if(parent[nod]&1)setHint(nod, poz, 1);
parent[nod]>>=1;
poz++;
}
poz=11;
while(nxt[nod]>0){
if(nxt[nod]&1)setHint(nod, poz, 1);
nxt[nod]>>=1;
poz++;
}
}
void dfs(int nod){
for(int i=0;i<adj[nod].size();i++)if(!visited[adj[nod][i]]){
visited[adj[nod][i]]=1;
nxt[ult_nod]=adj[nod][i];
ult_nod=adj[nod][i];
parent[adj[nod][i]]=nod;
dfs(adj[nod][i]);
}
}
void assignHints (int subtask , int N, int a[], int b[]){
n=N;
setHintLen(20);
adj.resize(n+5);
for(int i=1;i<n;i++){
adj[a[i]].push_back(b[i]);
adj[b[i]].push_back(a[i]);
}
ult_nod=1;
visited[1]=1;
dfs(1);
nxt[ult_nod]=0;
for(int i=1;i<=n;i++)hint(i);
}
void speedrun(int subtask , int N, int nod ){
int nr;
while(nod!=1){
nr=0;
for(int i=10;i>=1;i--)nr=(nr<<1)+getHint(i);
nod=nr;
goTo(nr);
}
int nxt=1;
while(1){
if(nxt==nod){
nr=0;
for(int j=20;j>=11;j--)nr=(nr<<1)+getHint(j);
nxt=nr;
if(!nxt)return;
}
if(goTo(nxt))nod=nxt;
else{
nr=0;
for(int j=10;j>=1;j--)nr=(nr<<1)+getHint(j);
nod=nr;
goTo(nr);
}
}
}
Compilation message
speedrun.cpp: In function 'void dfs(int)':
speedrun.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i=0;i<adj[nod].size();i++)if(!visited[adj[nod][i]]){
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
1072 KB |
Output is correct |
2 |
Correct |
55 ms |
1336 KB |
Output is correct |
3 |
Correct |
67 ms |
1604 KB |
Output is correct |
4 |
Correct |
54 ms |
1344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
1596 KB |
Output is correct |
2 |
Correct |
40 ms |
1704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
1596 KB |
Output is correct |
2 |
Correct |
47 ms |
1380 KB |
Output is correct |
3 |
Correct |
48 ms |
1084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
1600 KB |
Output is correct |
2 |
Correct |
56 ms |
1340 KB |
Output is correct |
3 |
Correct |
65 ms |
1476 KB |
Output is correct |
4 |
Correct |
54 ms |
1344 KB |
Output is correct |
5 |
Correct |
52 ms |
1476 KB |
Output is correct |
6 |
Correct |
54 ms |
1604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
1856 KB |
Output is correct |
2 |
Correct |
56 ms |
1596 KB |
Output is correct |
3 |
Correct |
59 ms |
1848 KB |
Output is correct |
4 |
Correct |
52 ms |
1484 KB |
Output is correct |
5 |
Correct |
55 ms |
1340 KB |
Output is correct |
6 |
Correct |
59 ms |
1348 KB |
Output is correct |
7 |
Correct |
48 ms |
1356 KB |
Output is correct |