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 "stations.h"
#include <bits/stdc++.h>
using namespace std;
struct Labeller {
int n, ord = 0;
vector<vector<int>> adj;
vector<int> labels;
Labeller(int n, const vector<int>& u, const vector<int>& v): n(n), adj(n), labels(n) {
for (int i = 0; i < n - 1; i++) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
preposterous(0, -1, false);
assert(ord == n);
}
void preposterous(int s, int p, bool x) {
if (x) labels[s] = ord++;
for (int t : adj[s]) if (t != p) preposterous(t, s, !x);
if (!x) labels[s] = ord++;
}
};
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
return Labeller(n, u, v).labels;
}
int find_next_station(int s, int t, vector<int> c) {
if (s > c.back()) reverse(c.begin(), c.end());
for (int u : c) if (min(u, s) <= t && t <= max(u, s)) return u;
return c.back();
}
# | 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... |