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 <stdlib.h>
#define N 1000
int *ej[N], eo[N];
void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
void bfs(int n, int s) {
static int dd[N], qu[N];
int i, g, head, cnt;
for (i = 0; i < n; i++)
dd[i] = n;
head = cnt = 0;
dd[s] = 0, qu[head + cnt++] = s;
while (cnt) {
int d, o;
i = qu[cnt--, head++], d = dd[i] + 1;
for (o = eo[i]; o--; ) {
int j = ej[i][o];
if (dd[j] > d)
dd[j] = d, qu[head + cnt++] = j;
}
}
for (i = 0; i < n; i++)
for (g = 0; g < 10; g++)
encode_bit(dd[i] >> g & 1);
}
void encode(int n, int k, int m, int *ii, int *jj) {
int h, i;
for (i = 0; i < n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
for (h = 0; h < m; h++)
append(ii[h], jj[h]), append(jj[h], ii[h]);
for (i = 0; i < k; i++)
bfs(n, i);
}
#include "grader.h"
#include "decoder.h"
void decode(int n, int k) {
int g, i, j;
for (i = 0; i < k; i++)
for (j = 0; j < n; j++) {
int d = 0;
for (g = 0; g < 10; g++)
if (decode_bit())
d |= 1 << g;
hops(i, j, d);
}
}
Compilation message (stderr)
encoder.c: In function 'append':
encoder.c:12:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
12 | if (o >= 2 && (o & o - 1) == 0)
| ~~^~~
# | 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... |