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 <bits/stdc++.h>
using namespace std;
#define PB push_back
#include "grader.h"
#include "encoder.h"
#define N 1010
static int p[N], d[N];
bool vis[N];
static vector<int> adj[N];
void dfs(int n) {
vis[n] = 1;
for(auto i : adj[n])
if(!vis[i])
dfs(i), p[i] = n;
}
void encode(int n, int h, int m, int *A, int *B) {
for(int i = 0; i < m; ++i) {
adj[A[i]].PB(B[i]);
adj[B[i]].PB(A[i]);
}
dfs(0);
for(int i = 1; i < n; ++i)
for(int j = 0; j < 10; ++j)
encode_bit(bool(p[i] & (1<<j)));
vector<int> x;
for(int i = 0; i < h; ++i) {
queue<int> q;
memset(d, -1, sizeof d);
q.push(i);
d[i] = 0;
while(!empty(q)) {
int u = q.front(); q.pop();
for(auto v : adj[u]) if(d[v] < 0)
d[v] = d[u] + 1, q.push(v);
}
for(int u = 1; u < n; ++u)
x.PB(1 + d[u] - d[p[u]]);
}
while(size(x) % 3) x.PB(0);
for(int i = 0; i < size(x); i += 3) {
int num = x[i] + x[i + 1] * 3 + x[i + 2] * 9;
for(int j = 0; j < 5; ++j)
encode_bit(bool(num & (1<<j)));
}
return;
}
#include <bits/stdc++.h>
using namespace std;
#include "grader.h"
#include "decoder.h"
#define N 1000
#define PB push_back
static int p[N], dif[N], H;
static vector<int> adj[N], x;
void dfs(int n, int par, int d) {
hops(H, n, d);
for(auto v : adj[n]) if(v != par)
dfs(v, n, d + (n == p[v] ? dif[v] : -dif[n]));
}
void decode(int n, int h) {
for(int i = 1; i < n; ++i) {
for(int j = 0; j < 10; ++j)
if(decode_bit()) p[i] |= 1<<j;
adj[i].PB(p[i]);
adj[p[i]].PB(i);
}
x.resize(n * h - h);
while(size(x) % 3) x.PB(0);
for(int i = 0; i < size(x); i += 3) {
int num=0;
for(int j = 0; j < 5; ++j)
if(decode_bit()) num |= 1<<j;
for(int j = 0; j < 3; ++j, num /= 3)
x[i + j] = (num % 3) - 1;
}
for(int pos = H = 0; H < h; ++H) {
for(int u = 1; u < n; ++u)
dif[u] = x[pos++];
dfs(H, H, 0);
}
}
Compilation message (stderr)
encoder.cpp: In function 'void encode(int, int, int, int*, int*)':
encoder.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i = 0; i < size(x); i += 3) {
| ~~^~~~~~~~~
decoder.cpp: In function 'void decode(int, int)':
decoder.cpp:23:19: 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 < size(x); i += 3) {
| ~~^~~~~~~~~
# | 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... |