Submission #835585

#TimeUsernameProblemLanguageResultExecution timeMemory
835585Desh03Stations (IOI20_stations)C++17
0 / 100
704 ms676 KiB
#include <bits/stdc++.h> using namespace std; const int lg = 10, N = 1000; vector<int> g[N]; int up[lg][N], in[N], en[N], dep[N], t; 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) { t = 0; for (int i = 0; i < n; i++) g[i].clear(); for (int i = 0; i < n - 1; i++) { g[u[i]].push_back(v[i]); g[v[i]].push_back(u[i]); } dep[0] = 0; 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...