Submission #329787

#TimeUsernameProblemLanguageResultExecution timeMemory
329787chenwzStations (IOI20_stations)C++14
100 / 100
997 ms1092 KiB
#include "stations.h" #include <vector> #include <algorithm> 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 (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; 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. return *lower_bound(c.begin(), c.end(), t); // t is in this subtree, Pick the smallest ch >= 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]; return *(upper_bound(c.begin(), c.end(), t) - 1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...