# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
386556 | PurpleCrayon | Meetings 2 (JOI21_meetings2) | C++17 | 695 ms | 44996 KiB |
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;
#define ar array
#define sz(v) int(v.size())
const int MAXN = 2e5+10, MAXL = 18, INF = 1e9+10;
int n, depth[MAXN], anc[MAXN][MAXL], st[MAXN], en[MAXN], tt=0;
vector<int> adj[MAXN];
//start lca
void init_lca(int c=0, int p=-1, int d=0){
depth[c]=d, anc[c][0]=p;
st[c] = tt++;
for (int i=1; i < MAXL; i++) anc[c][i] = (anc[c][i-1]==-1?-1:anc[anc[c][i-1]][i-1]);
for (auto nxt : adj[c]) if (nxt != p) init_lca(nxt, c, d+1);
en[c] = tt-1;
}
int jmp(int a, int h){
for (int i = 0; i < MAXL; i++) if ((h>>i)&1) a = anc[a][i];
return a;
}
int lca(int a, int b){
if (depth[a] < depth[b]) swap(a, b);
a = jmp(a, depth[a]-depth[b]);
if (a==b) return a;
for (int i = MAXL-1; i >= 0; i--){
if (anc[a][i] != anc[b][i]) a = anc[a][i], b = anc[b][i];
}
assert(anc[a][0]==anc[b][0]);
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |