제출 #835466

#제출 시각아이디문제언어결과실행 시간메모리
835466Desh03기지국 (IOI20_stations)C++17
0 / 100
6 ms804 KiB
#include <bits/stdc++.h> using namespace std; vector<vector<int>> g, up; vector<int> in, en, dep, rev; int t, lg; void dfs(int u) { rev[t] = 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 = rev = 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); return in; } 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) { s = rev[s], t = rev[t]; if (!upper(s, t)) return in[up[0][s]]; return in[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...