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 <bits/stdc++.h>
using namespace std;
const int lg = 20, N = 100000;
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 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... |