# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
117097 | Mamnoon_Siam | 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 "Encoder.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1 << 18;
const int half = 125001, full = 250000;
vector<int> g[maxn];
int tym = 0;
pair<int, int> optimize(int L, int R) {
int diff = R - L;
if(250000 - diff < diff) {
diff = 250000 - diff;
L = R;
} return {L, diff};
}
void dfs(int u, int p) {
int L = tym++, R, l, diff;
for(int v : g[u]) if(v - p) {
dfs(v, u);
} R = tym - 1;
tie(l, diff) = optimize(L, R);
Code(u, 1LL * l * 125001 + diff);
}
void Encode(int N, int A[], int B[]) {
for(int i = 0; i < N - 1; i++) {
int u = A[i], v = B[i];
g[u].emplace_back(v);
g[v].emplace_back(u);
} dfs(0, -1);
}