이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "stations.h"
#include <vector>
#include <algorithm>
std::vector<std::vector<int>> adj;
void dfs(int u, int p, int k, std::vector<int> &labels, int &r) {
if (k) labels[u] = r++;
for (int v : adj[u]) if (v != p) dfs(v, u, !k, labels, r);
if (!k) labels[u] = r++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
adj.assign(n, std::vector<int>(0));
for (int i = 0; i < (int) u.size(); ++i) {
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
std::vector<int> labels(n);
int r = 0;
dfs(0, -1, 1, labels, r);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
std::sort(c.begin(), c.end());
if (s == 0) {
return *std::lower_bound(c.begin(), c.end(), t);
} else if ((int) c.size() == 1) {
return c[0];
} else if (s < c[0]) {
if (t < s || c.back() < t) return c.back();
else return *std::lower_bound(c.begin(), c.end(), t);
} else {
if (t <= c[0] || s < t) return c[0];
return *prev(std::upper_bound(c.begin(), c.end(), t));
}
return c[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... |