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 "grader.h"
#include "encoder.h"
#include <bits/stdc++.h>
using namespace std;
static int n, h, p[1010], md[1010], v[1010];
static vector<int> e[1010], t[1010];
static queue<int> q;
void dfs(int x){
for(auto &i : e[x]){
if(p[i] != -1) continue;
p[i] = x;
dfs(i);
}
}
void fil(int x, int p){
for(auto &i : t[x]){
if(i == p) continue;
v[i] = md[i] - md[x] + 1;
fil(i, x);
}
}
void bfs(int x){
fill(md, md + n, 1e9);
md[x] = 0;
q.push(x);
while(!q.empty()){
int c = q.front(); q.pop();
for(auto &i : e[c]){
if(md[c] + 1 >= md[i]) continue;
md[i] = md[c] + 1;
q.push(i);
}
}
fil(x, -1);
v[x] = 1;
for(int i = 0; i < n; i += 5){
int t = 0;
for(int j = 0, k = 1; j < 5; j++, k *= 3) t += k * v[i + j];
for(int j = 0; j < 8; j++) encode_bit(!!(t & (1 << j)));
}
}
void encode(int nv, int nh, int ne, int *v1, int *v2){
n = nv;
h = nh;
for(int i = 0, x, y; i < ne; i++){
x = v1[i]; y = v2[i];
e[x].push_back(y);
e[y].push_back(x);
}
fill(p + 1, p + n, -1);
dfs(0);
for(int i = 1; i < n; i++){
for(int j = 0; j < 10; j++) encode_bit(!!(p[i] & (1 << j)));
}
for(int i = 1; i < n; i++){
t[i].push_back(p[i]);
t[p[i]].push_back(i);
}
for(int i = 0; i < h; i++){
bfs(i);
}
}
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>
using namespace std;
static int n, h, v[1010];
static vector<int> t[1010];
void get(int x, int p){
for(auto &i : t[x]){
if(i == p) continue;
v[i] += v[x];
get(i, x);
}
}
void decode(int nv, int nh){
n = nv;
h = nh;
for(int i = 1; i < n; i++){
int x = 0;
for(int j = 0; j < 10; j++) x += (decode_bit() << j);
t[x].push_back(i);
t[i].push_back(x);
}
for(int i = 0; i < h; i++){
for(int j = 0; j < n; j += 5){
int x = 0;
for(int k = 0; k < 8; k++) x += (decode_bit() << k);
for(int k = 0; k < 5; k++){
v[j + k] = x % 3 - 1;
x /= 3;
}
}
get(i, -1);
for(int j = 0; j < n; j++) hops(i, j, v[j]);
}
}
# | 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... |