# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
684182 | rainboy | City (JOI17_city) | C11 | 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 <stdlib.h>
static const int N = 250000;
static int *ej[N], eo[N];
static void append(int i, int j) {
int o = eo[i]++;
if (o >= 2 && (o & o - 1) == 0)
ej[i] = (int *) realloc(ej[i], o * 2 * sizeof *ej[i]);
ej[i][o] = j;
}
static int ta[N], tb[N], time;
static void dfs(int p, int i) {
ta[i] = time++;
for (int o = eo[i]; o--; ) {
int j = ej[i][o];
if (j != p)
dfs(i, j);
}
tb[i] = time;
}
static long long f(int a, int b) {
return (long long) b * (b - 1) / 2 + a;
}
void Encode(int n, int ii[], int jj[]) {
for (int i = 0; i < n; i++)
ej[i] = (int *) malloc(2 * sizeof *ej[i]);
for (int h = 0; h < n - 1; h++)
append(ii[h], jj[h]), append(jj[h], ii[h]);
time = 0, dfs(-1, 0);
for (int i = 0; i < n; i++)
Code(i, f(ta[i], tb[i]));
}
#include "Device.h"
static const int N = 250000;
void InitDevice() {}
static void g(long long x, int *a_, int *b_) {
int lower = 1, upper = N + 2;
while (upper - lower > 1) {
int b = (lower + upper) / 2;
if (x >= (long long) b * (b - 1) / 2)
lower = b;
else
upper = b;
}
*b_ = lower, *a_ = x - (long long) lower * (lower - 1) / 2;
}
int Answer(long long x, long long y) {
int tai, tbi, taj, tbj;
g(x, &tai, &tbi), g(y, &taj, &tbj);
if (taj <= tai && tbi <= tbj)
return 0;
if (tai <= taj && tbj <= tbi)
return 1;
return 2;
}