#include "grader.h"
#include "encoder.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n;
int par[maxn];
int d[36][maxn];
vector <int> adj[maxn];
void bfs(int rt, bool keep)
{
queue<int> q;
fill_n(d[rt],n,-1);
d[rt][rt] = 0;
q.push(rt);
if (keep) par[rt] = rt;
while (!q.empty())
{
int u=q.front(); q.pop();
for (int v:adj[u])
if (d[rt][v] == -1)
{
d[rt][v] = d[rt][u] + 1;
if (keep) par[v] = u;
q.push(v);
}
}
}
inline bool checkbit(int i, int j)
{
return i>>j&1;
}
void encode(int nv, int nh, int ne, int *v1, int *v2){
n=nv;
for (int i=0; i<n; i++) adj[i].clear();
for (int i=0; i<ne; i++)
{
int u=v1[i]; int v=v2[i];
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i=0; i<nh; i++) bfs(i,(i==0));
for (int i=0; i<n; i++)
{
for (int j=0; j<10; j++)
{
// cerr<<i<<' '<<j<<' '<<par[i]<<" : "<<checkbit(par[i],j)<<endl;
encode_bit(checkbit(par[i],j));
}
}
// for (int i=0; i<n; i++) cerr<<d[0][i]<<" : "; cerr<<endl;
// for (int i=0; i<n; i++) cerr<<d[1][i]<<" : "; cerr<<endl;
par[n]=par[n+1]=par[n+2]=0;
for (int rt=1; rt<nh; rt++)
for (int i=1; i<n; i+=3)
{
int u,v;
u=i; v=par[i];
// cerr<<u<<" - "<<v<<endl;
int t1 = (d[rt][u]==d[rt][v])?0:((d[rt][u]>d[rt][v])?1:2);
u=i+1; v=par[i+1];
int t2 = (d[rt][u]==d[rt][v])?0:((d[rt][u]>d[rt][v])?1:2);
u=i+2; v=par[i+2];
int t3 = (d[rt][u]==d[rt][v])?0:((d[rt][u]>d[rt][v])?1:2);
int T = t1+t2*3+t3*9;
// cerr<<t1<<" & "<<t2<<" & "<<t3<<endl;
for (int z=0; z<=5; z++) encode_bit(checkbit(T,z));
}
}
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>
using namespace std;
int _n,_rt;
vector <int> _adj[maxn];
int _par[maxn];
int _d[maxn],_t[maxn],_ans[maxn];
void _BFS()
{
queue<int> q;
fill_n(_d,_n,-1);
_d[0] = 0;
q.push(0);
while (!q.empty())
{
int u=q.front(); q.pop();
for (int v:_adj[u])
if (_d[v]==-1)
{
_d[v]=_d[u]+1;
q.push(v);
}
}
}
void dfs(int x, int p)
{
for (int i:_adj[x])
if (i!=p)
{
if (_t[i]==0) _ans[i]=_ans[x];
else if (_t[i]==1) _ans[i]=_ans[x]+1;
else _ans[i]=_ans[x]-1;
dfs(i,x);
}
}
void decode(int nv, int nh) {
_n=nv; _rt = 0;
// cerr<<nv<<' '<<nh<<endl;
for (int i=0; i<_n; i++)
{
int x=0;
for (int j=0; j<10; j++) if (decode_bit()) x|=(1<<j);
_par[i] = x;
_adj[_par[i]].push_back(i);
// cerr<<_par[i]<<" -> "<<i<<endl;
}
_BFS();
// for (int i=0; i<_n; i++) cerr<<_d[i]<<' '; cerr<<endl;
for (int i=0; i<_n; i++) hops(_rt,i,_d[i]);
for (int st = 1; st<nh; st++)
{
// cerr<<st<<endl;
for (int i=1; i<_n; i+=3)
{
int T = 0;
for (int z=0; z<=5; z++) if (decode_bit()) T |= (1<<z);
int t1 = T%3; T/=3;
int t2 = T%3; T/=3;
int t3 = T%3; T/=3;
_t[i]=t1; _t[i+1]=t2; _t[i+2]=t3;
}
// for (int i=1; i<_n; i++) cerr<<_t[i]<<' '; cerr<<endl;
_ans[0] = _d[st];
dfs(0,0);
// for (int i=0; i<_n; i++) cerr<<_ans[i]<<' '; cerr<<endl;
for (int i=0; i<_n; i++) hops(st,i,_ans[i]);
}
}
Compilation message
decoder.cpp:7:19: error: 'maxn' was not declared in this scope
7 | vector <int> _adj[maxn];
| ^~~~
decoder.cpp:8:10: error: 'maxn' was not declared in this scope
8 | int _par[maxn];
| ^~~~
decoder.cpp:9:8: error: 'maxn' was not declared in this scope
9 | int _d[maxn],_t[maxn],_ans[maxn];
| ^~~~
decoder.cpp:9:17: error: 'maxn' was not declared in this scope
9 | int _d[maxn],_t[maxn],_ans[maxn];
| ^~~~
decoder.cpp:9:28: error: 'maxn' was not declared in this scope
9 | int _d[maxn],_t[maxn],_ans[maxn];
| ^~~~
decoder.cpp: In function 'void _BFS()':
decoder.cpp:13:12: error: '_d' was not declared in this scope; did you mean '_n'?
13 | fill_n(_d,_n,-1);
| ^~
| _n
decoder.cpp:19:20: error: '_adj' was not declared in this scope
19 | for (int v:_adj[u])
| ^~~~
decoder.cpp: In function 'void dfs(int, int)':
decoder.cpp:29:16: error: '_adj' was not declared in this scope
29 | for (int i:_adj[x])
| ^~~~
decoder.cpp:32:13: error: '_t' was not declared in this scope; did you mean '_rt'?
32 | if (_t[i]==0) _ans[i]=_ans[x];
| ^~
| _rt
decoder.cpp:32:23: error: '_ans' was not declared in this scope; did you mean '_n'?
32 | if (_t[i]==0) _ans[i]=_ans[x];
| ^~~~
| _n
decoder.cpp:33:28: error: '_ans' was not declared in this scope; did you mean '_n'?
33 | else if (_t[i]==1) _ans[i]=_ans[x]+1;
| ^~~~
| _n
decoder.cpp:34:14: error: '_ans' was not declared in this scope; did you mean '_n'?
34 | else _ans[i]=_ans[x]-1;
| ^~~~
| _n
decoder.cpp: In function 'void decode(int, int)':
decoder.cpp:45:9: error: '_par' was not declared in this scope
45 | _par[i] = x;
| ^~~~
decoder.cpp:46:9: error: '_adj' was not declared in this scope
46 | _adj[_par[i]].push_back(i);
| ^~~~
decoder.cpp:51:41: error: '_d' was not declared in this scope; did you mean '_n'?
51 | for (int i=0; i<_n; i++) hops(_rt,i,_d[i]);
| ^~
| _n
decoder.cpp:62:13: error: '_t' was not declared in this scope; did you mean 'st'?
62 | _t[i]=t1; _t[i+1]=t2; _t[i+2]=t3;
| ^~
| st
decoder.cpp:65:9: error: '_ans' was not declared in this scope; did you mean '_n'?
65 | _ans[0] = _d[st];
| ^~~~
| _n
decoder.cpp:65:19: error: '_d' was not declared in this scope; did you mean '_n'?
65 | _ans[0] = _d[st];
| ^~
| _n