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 <bits/stdc++.h>
using namespace std;
void encode_number(int n,int N, int H)
{
for(int i = 1<<9; i > 0; i>>=1)
{
encode_bit((n&i)>0);
}
}
int count1 = 0;
int count0 = 0;
int countm1 = 0;
void encode(int N, int H, int P, int *A, int *B)
{
vector<vector<int>> neigh(N);
for(int i = 0; i < P; i++)
{
neigh[A[i]].push_back(B[i]);
neigh[B[i]].push_back(A[i]);
}
// BFS from all H
vector<vector<int>> distance(H,vector<int>(N,INT_MAX));
for(int h = 0; h < H; h++)
{
queue<pair<int,int>> q;
q.push({h,0});
while(q.size())
{
auto v = q.front();q.pop();
if(distance[h][v.first]!=INT_MAX) continue;
distance[h][v.first] = v.second;
for(auto i : neigh[v.first]) q.push({i,v.second+1});
}
}
vector<int> treep(N,-1);
queue<int> q;
q.push(0);
while(q.size())
{
auto v = q.front();q.pop();
for(auto i : neigh[v])
{
if(treep[i]!=-1) continue;
treep[i] = v;
q.push(i);
}
}
for(int i = 1; i < N; i++)
{
int p = treep[i];
encode_number(p,N,H);
}
for(int i = 1; i < N; i++)
{
int p = treep[i];
for(int h=1; h < H; h++)
{
switch(distance[h][i]-distance[h][p])// mostly 1, sometimes -1, rarely 0
{
case 0:
encode_bit(1);
count0++;
break;
case 1:
encode_bit(0);encode_bit(1);
count1++;
break;
case -1:
encode_bit(0);encode_bit(0);
countm1++;
break;
}
}
}
//cout << "counts = " << count1 << " " << count0 << " " << countm1 << "\n";
}
#include "grader.h"
#include "decoder.h"
#include <bits/stdc++.h>
using namespace std;
int decode_number(int N,int H)
{
int o=0;
for(int i = 0; i < 10; i++) o = (o<<1)+decode_bit();
return o;
}
void decode(int N, int H) {
vector<int> treep(N,-1);
vector<vector<int>> treec(N);
vector<vector<int>> distance(N,vector<int>(H,INT_MAX));
vector<vector<int>> delta(N,vector<int>(H,0));
for(int i = 0; i < H; i++) distance[i][i] = 0;
for(int i = 1; i < N; i++)
{
treep[i] = decode_number(N, H);
treec[treep[i]].push_back(i);
}
for(int i = 1; i < N; i++)
{
delta[i][0] = 1;
for(int h = 1; h < H; h++)
{
if(decode_bit())
{
delta[i][h] = 0;
continue;
}
if(decode_bit())
{
delta[i][h] = 1;
}
else
{
delta[i][h] = -1;
}
}
}
for(int h = 1; h < H; h++)
{
int c = 0;
int t = h;
while(t!=0)
{
c += delta[t][h];
t = treep[t];
}
distance[0][h] = -c;
}
queue<int> q;
for(auto i : treec[0]) q.push(i);
while(q.size())
{
auto v = q.front(); q.pop();
for(int h = 0; h < H; h++)
{
distance[v][h] = distance[treep[v]][h] + delta[v][h];
}
for(auto i : treec[v]) q.push(i);
}
for(int h = 0; h < H; h++)
for(int c = 0; c < N; c++)
hops(h,c,distance[c][h]);
}
# | 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... |