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 <vector>
#include <queue>
using namespace std;
static int n;
static const int inf = 1e5;
static int dist[36][1000];
static int pr[36][1000];
static vector<int> edge[1000];
void bfs(int dist[], int pr[], int s) {
for (int i = 0; i < n; ++i) dist[i] = inf;
dist[s] = 0;
queue<int> q;
q.push(s);
while (!q.empty()) {
int x = q.front(); q.pop();
for (int i : edge[x]) {
if (dist[i] < inf) continue;
dist[i] = dist[x] + 1;
pr[i] = x;
q.push(i);
}
}
}
void encode(int N, int H, int M, int * A, int * B) {
n = N;
for (int i = 0; i < M; ++i) {
edge[A[i]].push_back(B[i]);
edge[B[i]].push_back(A[i]);
}
for (int i = 0; i < H; ++i) bfs(dist[i], pr[i], i);
for (int i = 1; i < N; ++i) {
for (int j = 10; j--; ) {
encode_bit((pr[0][i] >> j) & 1);
}
}
for (int i = 1; i < H; ++i) {
for (int j = 1; j < N; ++j) {
int x = dist[i][j] - dist[i][pr[0][j]] + 1;
encode_bit((x >> 1) & 1);
encode_bit(x & 1);
}
}
}
#include "grader.h"
#include "decoder.h"
#include <vector>
using namespace std;
static int d[1000];
static int dist[1000];
static vector<int> edge[1000];
void dfs(int x) {
for (int i : edge[x]) dist[i] = dist[x] + d[i], dfs(i);
}
void decode(int N, int H) {
for (int i = 1; i < N; ++i) {
int x = 0;
for (int j = 0; j < 10; ++j) {
x <<= 1;
x ^= decode_bit();
}
d[i] = 1;
edge[x].push_back(i);
}
dist[0] = 0;
dfs(0);
for (int i = 0; i < N; ++i) hops(0, i, dist[i]);
for (int i = 1; i < H; ++i) {
for (int j = 1; j < N; ++j) {
int x = decode_bit() << 1;
x ^= decode_bit();
d[j] = x - 1;
}
dfs(0);
for (int j = 0; j < N; ++j) hops(i, j, dist[j] - dist[i]);
}
}
# | 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... |