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 <bits/stdc++.h>
using namespace std;
#include "stations.h"
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
vector<int> tin(n), tout(n), depth(n);
int timer = 0;
vector<vector<int>> adj(n);
for (int i = 0; i < n - 1; i++) {
adj[u[i]].emplace_back(v[i]);
adj[v[i]].emplace_back(u[i]);
}
function<void(int, int)> dfs = [&](int u, int p) {
tin[u] = timer;
if (depth[u] == 0) timer++;
for (int v : adj[u]) {
if (v == p) continue;
depth[v] = depth[u] ^ 1;
dfs(v, u);
}
tout[u] = timer;
if (depth[u] == 1) timer++;
};
dfs(0, -1);
vector<int> ans(n);
for (int i = 0; i < n; i++) {
ans[i] = depth[i] ? tout[i] : tin[i];
}
return ans;
}
int find_next_station(int s, int t, std::vector<int> c) {
if (s < c[0]) {
if (s == 0) {
/// s' = 0
return *lower_bound(c.begin(), c.end(), t);
} else {
int touts = c.back();
int tins = s;
if (tins <= t && t <= touts) {
return *lower_bound(c.begin(), c.end(), t);
} else {
return c.back();
}
}
} else if (s > c.back()) {
int tins = c[0];
int touts = s;
if (tins <= t && t <= touts) {
return *(--upper_bound(c.begin(), c.end(), t));
} else {
return c[0];
}
}
return -1;
}
# | 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... |