Common Ancestors
Ayush has two rooted trees. Each of them contains $N$ vertices (numbered $1$ through $N$); let's denote a vertex $v$ in tree $1$ by $v_1$ and a corresponding vertex $v$ in tree $2$ by $v_2$. For each tree $t$, any vertex on the path from the root to a vertex $v_t$ (including $v_t$) is an ancestor of $v_t$ and the depth of $v_t$ is the distance of $v_t$ from the root of tree $t$. For any integer
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