Skip to main content

Ancestors and LCA under Load

Challenge on lesson: Checkpoint — Lifting and LCA

CHALLENGE
Difficulty: advanced+25 XP

**Bài toán.** A rooted tree with n nodes (root 1; the parent of v is given for v = 2..n). q queries: LCA u v prints the lowest common ancestor; ANC v k prints the k-th ancestor of v (or 0 if it does not exist). **Constraints:** 1 ≤ n, q ≤ 200 000; 0 ≤ k < n. Binary lifting with LOG = 18 covers both query types in O(log n).

Back to lesson: Checkpoint — Lifting and LCA