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 <vector>
#include <cassert>
#include <cmath>
#include <algorithm>
namespace {
void do_label(const std::vector<std::vector<int>>& adj, std::vector<int>& labels, int& cur_idx, int cur, int prv, bool dir) {
if (!dir) {
labels[cur] = cur_idx++;
}
for (int nxt : adj[cur]) {
if (nxt == prv) continue;
do_label(adj, labels, cur_idx, nxt, cur, !dir);
}
if (dir) {
labels[cur] = cur_idx++;
}
}
}
std::vector<int> label(int N, int K, std::vector<int> U, std::vector<int> V) {
std::vector<std::vector<int>> adj(N);
for (int e = 0; e < N-1; e++) {
adj[U[e]].push_back(V[e]);
adj[V[e]].push_back(U[e]);
}
std::vector<int> labels(N);
int cur_idx = 0;
do_label(adj, labels, cur_idx, 0, -1, false);
assert(cur_idx-1 <= K);
return labels;
}
int find_next_station(int S, int T, std::vector<int> C) {
assert(S != T);
assert(!C.empty());
if (C.front() < S) {
if (T > S || T <= C.front()) return C.front();
auto it = --std::upper_bound(C.begin(), C.end(), T);
return *it;
} else {
if (T < S || T >= C.back()) return C.back();
auto it = std::lower_bound(C.begin(), C.end(), T);
return *it;
}
}
# | 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... |