Submission #304944

#TimeUsernameProblemLanguageResultExecution timeMemory
304944ecnerwalaStations (IOI20_stations)C++17
100 / 100
1154 ms1044 KiB
#include "stations.h" #include <vector> #include <cassert> #include <cmath> #include <algorithm> namespace { void do_label(const std::vector<std::vector<int>>& adj, std::vector<int>& labels, int& cur_idx, int cur, int prv, bool dir) { if (!dir) { labels[cur] = cur_idx++; } for (int nxt : adj[cur]) { if (nxt == prv) continue; do_label(adj, labels, cur_idx, nxt, cur, !dir); } if (dir) { labels[cur] = cur_idx++; } } } std::vector<int> label(int N, int K, std::vector<int> U, std::vector<int> V) { std::vector<std::vector<int>> adj(N); for (int e = 0; e < N-1; e++) { adj[U[e]].push_back(V[e]); adj[V[e]].push_back(U[e]); } std::vector<int> labels(N); int cur_idx = 0; do_label(adj, labels, cur_idx, 0, -1, false); assert(cur_idx-1 <= K); return labels; } int find_next_station(int S, int T, std::vector<int> C) { assert(S != T); assert(!C.empty()); if (C.front() < S) { if (T > S || T <= C.front()) return C.front(); auto it = --std::upper_bound(C.begin(), C.end(), T); return *it; } else { if (T < S || T >= C.back()) return C.back(); auto it = std::lower_bound(C.begin(), C.end(), T); return *it; } }
#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...