Kth ancestor of the node
CodeChefOpen on judge ↗
Given an undirected connected tree with **n** nodes, numbered from **1** to **n**, and rooted at node **1**, and two positive integer $k$ and $v$, find the **$k^{th}$** ancestor (Ancestor at $k$ level up. Parent of a node is also an ancestor 1 level up) of the node $v$. For example, in the following tree, the 2nd ancestor of node $7$ is node $1$. ![Kth Nodes](https://cdn.codechef.com/images/le
HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17
CodeSearch Tutor
Hints, not spoilers — it won’t hand over the full solution unless you insist.
Sign in to chat with the tutor and save your progress.
Sign in to start