제출 #956376

#제출 시각아이디문제언어결과실행 시간메모리
956376Desh03기지국 (IOI20_stations)C++17
0 / 100
514 ms1836 KiB
#include <bits/stdc++.h> using namespace std; const int lg = 15, N = 10000; vector<int> g[N]; int up[lg][N], in[N], en[N], dep[N], t; void dfs(int u) { for (int v : g[u]) { g[v].erase(find(g[v].begin(), g[v].end(), u)); in[v] = t++; up[0][in[v]] = in[u]; for (int i = 1; i < lg; i++) { up[i][in[v]] = up[i - 1][up[i - 1][in[v]]]; } dep[in[v]] = dep[in[u]] + 1; dfs(v); } en[in[u]] = t; } bool upper(int u, int v) { return u <= v && en[v] <= en[u]; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { 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]); } in[0] = t++; dep[in[0]] = 0; for (int i = 0; i < lg; i++) { up[i][in[0]] = in[0]; } dfs(0); vector<int> ret(n); for (int i = 0; i < n; i++) { ret[i] = in[i]; } 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...