# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1174465 | _ncng.nyr | Cat in a tree (BOI17_catinatree) | C++20 | 1095 ms | 30256 KiB |
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, D, it;
int in[N], out[N], h[N];
int up[20][N];
vector<int> ad[N];
void init(int u, int p) {
in[u] = ++it;
if(u == 1) for(int i = 0; i <= 18; ++i) up[i][u] = u;
else for(int i = 1; i <= 18; ++i) up[i][u] = up[i - 1][up[i - 1][u]];
for(auto v : ad[u]) {
if(v == p) continue;
up[0][v] = u;
h[v] = h[u] + 1;
init(v, u);
}
out[u] = it;
}
int anc(int u, int v) {
return (in[u] <= in[v] && out[v] <= out[u]);
}
int lca(int u, int v) {
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |