이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "stations.h"
template <class T>
using Vec = std::vector<T>;
Vec<int> label(int n, int k, Vec<int> u, Vec<int> v) {
Vec<Vec<int>> graph(n);
for (int i = 0; i < n - 1; ++i) {
graph[u[i]].push_back(v[i]);
graph[v[i]].push_back(u[i]);
}
int time = 0;
Vec<int> ret(n);
auto dfs = [&](auto dfs, const int u, const int p, const int d) -> void {
const auto in = time++;
for (const auto v: graph[u]) {
if (v != p) {
dfs(dfs, v, u, d + 1);
}
}
const auto out = time++;
ret[u] = (d % 2 == 0 ? in : out);
};
dfs(dfs, 0, -1, 0);
return ret;
}
int find_next_station(int s, int t, Vec<int> c) {
if (c.size() == 1) {
return c[0];
}
std::sort(c.begin(), c.end());
if (s == 0) {
return *std::lower_bound(c.begin(), c.end(), t);
}
if (s < c.front()) {
const auto p = c.back();
c.pop_back();
if (s < t && t <= c.back()) {
return *std::lower_bound(c.begin(), c.end(), t);
}
else {
return p;
}
}
else {
const auto p = c.front();
c.erase(c.begin());
if (c.front() <= t && t < s) {
return *std::prev(std::upper_bound(c.begin(), c.end(), t));
}
else {
return p;
}
}
}
# | 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... |