Submission #835451

#TimeUsernameProblemLanguageResultExecution timeMemory
835451Desh03Stations (IOI20_stations)C++17
0 / 100
5 ms804 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<int>> g, up; vector<int> in, en, dep; int t, lg; void dfs(int u) { in[u] = t++; for (int i = 1; i < lg; i++) { up[i][u] = up[i - 1][up[i - 1][u]]; } for (int v : g[u]) { if (up[0][u] ^ v) { up[0][v] = u; dep[v] = dep[u] + 1; dfs(v); } } en[u] = t; } bool upper(int u, int v) { return in[u] <= in[v] && en[v] <= en[u]; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { lg = t = 0, g = vector<vector<int>> (n), in = en = dep = vector<int> (n); while ((1 << lg) <= n) ++lg; up = vector<vector<int>> (lg, vector<int> (n)); for (int i = 0; i < n - 1; i++) { g[u[i]].push_back(v[i]); g[v[i]].push_back(u[i]); } dfs(0); vector<int> ret(n); iota(ret.begin(), ret.end(), 0); return ret; } int kth(int u, int k) { for (int i = 0; i < lg; i++) { if (k >> i & 1) { u = up[i][u]; } } return u; } int find_next_station(int s, int t, vector<int> c) { if (!upper(s, t)) return up[0][s]; return kth(t, dep[t] - dep[s] - 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...