#include "speedrun.h"
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <cstring>
#include <unordered_map>
using namespace std;
typedef long long ll;
vector<ll>d[1007];
void assignHints(int subtask, int n, int a[], int b[]) { /* your solution here */
for(int i = 1; i < n; i++){
d[a[i]].push_back(b[i]);
d[b[i]].push_back(a[i]);
}
setHintLen(316);
int sz = sqrt(n);
for(int i = 1; i <= n; i++){
if(d[i].size() <= sz){ // the degree is less/equal than sqrt(n) => we can build an adjestancy list (10 bits per vertex)
int pos = 1;
for(auto x: d[i]){
for(int j = pos; j <= pos + 9; j++){
if((x >> (j - pos)) % 2 != 0)
setHint(i, j, 1);
}
pos += 10;
}
}
// else: leave it as it is, we're gonna check all N nodes using goTo later in speedrun
}
}
bool used[1007];
void dfs(ll v, ll par, int &n){
used[v] = true;
bool ok = false;
for(int i = 1; i <= 316; i++){
if(getHint(i))
ok = true;
}
if(!ok){ // there are no set bits, thus this node has degree > sqrt(n) and we can traverse over all N nodes using goTo (the amount of such nodes will not exceed sqrt(N) - why? idk, just seems logical, search for proof)
for(int i = 1; i <= n; i++){
if(goTo(i))
dfs(i, v, n);
}
}
else{ // this node has its adjactency list
for(int i = 1; i <= 316; i += 10){ // the start of new code
ll v2 = 0;
for(int j = 9; j >= 0; j--){
v2 *= 2;
if(getHint(i + j))
v2++;
}
if(!used[v2]){
goTo(v2);
dfs(v2, v, n);
}
}
}
if(par != -1) // go back, from where we've come
goTo(par);
}
void speedrun(int subtask, int n, int start) { /* your solution here */
dfs(start, -1, n);
}
Compilation message
speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:37:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
37 | if(d[i].size() <= sz){ // the degree is less/equal than sqrt(n) => we can build an adjestancy list (10 bits per vertex)
| ~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
77 ms |
684 KB |
Invalid node index to goTo |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
The length is too large |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
The length is too large |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
70 ms |
724 KB |
Invalid node index to goTo |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
The length is too large |
2 |
Halted |
0 ms |
0 KB |
- |