This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "stations.h"
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |