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 <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... |