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>
using namespace std;
typedef vector<int> VI;
void dfs(int u, int fa, bool dfs_in, int &clock, const vector<VI>& G, VI& L) {
if (dfs_in) L[u] = clock++;
for (int i : G[u])
if (i != fa) dfs(i, u, !dfs_in, clock, G, L);
if (!dfs_in) L[u] = clock++;
}
VI label(int n, int k, VI u, VI v) {
VI L(n);
vector<VI> G(n, VI());
for (size_t i = 0; i < u.size(); i++)
G[u[i]].push_back(v[i]), G[v[i]].push_back(u[i]);
int clock = 0;
dfs(0, -1, true, clock, G, L);
return L;
}
int find_next_station(int s, int t, VI c) {
int c0 = c[0];
if (c0 > s) { // Case 1: s is Tin. All the neighbors' label > s.
if (t < s || t > c.back()) return c.back(); // t not in this subtree, go to parent.
return *lower_bound(c.begin(), c.end(), t); // t is in this subtree, Pick the smallest ch >= t
}
// Case 2: s is Tout level.
if (t < c0 || t > s) return c0; // t not in subtree, go to root
return *(upper_bound(c.begin(), c.end(), t) - 1); // last v that <= t
}
// int main(){
// return 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... |