Practice · 1 of 2
k-th Ancestor
CHALLENGE
Difficulty: advanced+25 XP
**Bài toán.** A rooted tree (root 1), parents for v = 2..n. q queries
v k: print the k-th ancestor of v, or 0 if it does not exist.
**Constraints:** 1 ≤ n, q ≤ 200 000; 0 ≤ k ≤ n. One sparse table, O(log n)
per query.
Press Submit to check your solution.
Back to lesson: Practice: Lifting Drills