# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
130635 | RezwanArefin01 | City (JOI17_city) | C++17 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
#include "Encoder.h"
using namespace std;
const int N = 2e5 + 5;
vector<int> a, adj[N];
int in[N], sz[N], idx;
void build() {
double r = pow(2, 20.0 / 256.0);
a.push_back(1);
while(a.size() < 256) {
int x = a.back() * r;
if(x == a.back()) ++x;
a.push_back(x);
}
}
void dfs(int u, int p) {
in[u] = idx++, sz[u] = 1;
for(int v : adj[u]) if(v - p) {
dfs(v, u);
sz[u] += sz[v];
}
int opt = lower_bound(a.begin(), a.end(), sz[u]) - a.begin();
sz[u] = a[opt];
idx = in[u] + sz[u];
Code(u, ((long long)in[u] << 8) | opt);
}
void Encode(int n, int A[], int B[]) {
build();
for(int i = 0; i < n - 1; ++i) {
adj[A[i]].push_back(B[i]);
adj[B[i]].push_back(A[i]);
}
dfs(0, -1);
}