#include "grader.h"
#include "encoder.h"
#include <bits/stdc++.h>
using namespace std;
void encode(int nv, int nh, int ne, int *v1, int *v2) {
const int STORING_BITS = 10;
vector<vector<int>> g(nv);
vector<int> parrent(nv, -2);
vector<bool> vis(nv, 0);
for (int i = 0; i < ne; i++) {
g[v1[i]].push_back(v2[i]);
g[v2[i]].push_back(v1[i]);
}
function<void(int)> dfs = [&] (int a) {
vis[a] = 1;
for (auto &b : g[a]) {
if (!vis[b]) {
parrent[b] = a;
dfs(b);
}
}
};
parrent[0] = -1;
dfs(0);
int cnt = 0;
for (int i = 1; i < nv; i++) {
for (int bit = 0; bit < STORING_BITS; bit++) {
if (parrent[i] & (1 << bit)) {
encode_bit(1);
cnt++;
} else {
encode_bit(0);
cnt++;
}
}
}
vector<int> stored;
for (int i = 0; i < nh; i++) {
/// calculate the dist from vertex i
vector<int> d(nv, -1);
queue<int> q;
q.push(i);
d[i] = 0;
while (!q.empty()) {
int a = q.front();
q.pop();
for (auto &b : g[a]) {
if (d[b] == -1) {
d[b] = 1 + d[a];
q.push(b);
}
}
}
for (int i = 0; i < nv; i++) {
assert(d[i] != -1);
}
for (int i = 1; i < nv; i++) {
int dif = d[i] - d[parrent[i]];
assert(-1 <= dif && dif <= +1);
stored.push_back(dif + 1);
}
continue;
cout << " : ";
for (int i = 0; i < nv; i++) {
cout << d[i] << " ";
}
cout << "\n";
}
for (auto &send : stored) {
assert(0 <= send && send <= 2);
if (send == 0) {
encode_bit(0);
encode_bit(0);
}
if (send == 1) {
encode_bit(0);
encode_bit(1);
}
if (send == 2) {
encode_bit(1);
encode_bit(0);
}
}
return;
assert((int) stored.size() == nh * (nv - 1));
for (int i = 0; i < nv; i++) {
cout << i << " : " << parrent[i] << "\n";
}
cout << " = ";
for (auto &x : stored) {
cout << x << " ";
}
cout << "\n";
return;
exit(0);
encode_bit(1);
encode_bit(0);
return;
}
Compilation message
/usr/bin/ld: /tmp/cco0gzpB.o: in function `main':
grader_decoder.c:(.text.startup+0x126): undefined reference to `decode(int, int)'
collect2: error: ld returned 1 exit status