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>
using namespace std;
typedef vector<int> IVec;
void rec(int u, int fa, bool dfs_in, int &clock, const vector<IVec>& G, IVec& L) {
if (dfs_in) L[u] = clock++;
for (int i : G[u])
if (i != fa) rec(i, u, !dfs_in, clock, G, L);
if (!dfs_in) L[u] = clock++;
}
IVec label(int n, int k, IVec u, IVec v) {
IVec L(n);
vector<IVec> G(n, IVec());
for (int i = 0; i < u.size(); i++)
G[u[i]].push_back(v[i]), G[v[i]].push_back(u[i]);
int clock = 0;
rec(0, -1, true, clock, G, L);
return L;
}
int find_next_station(int s, int t, IVec c) {
if (c[0] > s) { // Case 1: s is in InClock. All the neighbors' label > s.
if (t < s || t > c.back()) return c.back(); // t not in this subtree, go to parent.
int v = 0; // t is in this subtree, Pick the smallest ch >= t
return *lower_bound(c.begin(), c.end(), t);
}
if (t < c[0]) // Case 2: node s is in the post_order level.
return c[0]; // t not in subtree
if (t > s) return c[0]; // t not in this subtree, go to the root.
int v = c.size() - 1;
while (c[v] > t) v--;
return c[v];
}
Compilation message (stderr)
stations.cpp: In function 'IVec label(int, int, IVec, IVec)':
stations.cpp:16:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int i = 0; i < u.size(); i++)
| ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, IVec)':
stations.cpp:26:9: warning: unused variable 'v' [-Wunused-variable]
26 | int v = 0; // t is in this subtree, Pick the smallest ch >= t
| ^
# | 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... |