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>
struct Node {
std::vector <int> nei;
int d, a, b;
Node() : d(0), a(0), b(0) { }
};
struct Triplet {
int x, y, z;
Triplet(int X = 0, int Y = 0, int Z = 0) : x(X), y(Y), z(Z) { }
bool operator<(const Triplet& other) const {
if (x == other.x) return y > other.y;
return x < other.x;
}
};
int cnt;
void dfs(std::vector <Node>& g, int node = 0, int par = -1) {
g[node].a = cnt++;
g[node].d = par == -1 ? 0 : g[par].d + 1;
for (int x : g[node].nei) if (x != par) dfs(g, x, node);
g[node].b = cnt - 1;
}
std::vector <int> label(int n, int k, std::vector <int> u, std::vector <int> v) {
cnt = 0;
std::vector <int> r(n);
std::vector <Node> g(n);
for (int i = 0; i < n - 1; i++) {
g[u[i]].nei.push_back(v[i]);
g[v[i]].nei.push_back(u[i]);
}
dfs(g);
std::vector <Triplet> tr(n);
for (int i = 0; i < n; i++) tr[i] = Triplet(g[i].d & 1 ? g[i].b : g[i].a, g[i].d, i);
std::sort(tr.begin(), tr.end());
for (int i = 0; i < n; i++) r[tr[i].z] = i;
return r;
}
int find_next_station(int s, int t, std::vector <int> c) {
if (!(c.size() - 1)) return c.front();
if (!s) for (int x : c) if (t <= x) return x;
if (s < c.front()) {
if (!(s <= t && t <= c[c.size() - 2])) return c.back();
for (int x : c) if (t <= x) return x;
}
if (!(t <= s && c[1] <= t)) return c.front();
for (int i = (int)c.size() - 1; i >= 0; i--) if (c[i] <= t) return c[i];
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |