← All problemsSign in

The Closest Vertex

You are given a rooted tree with n vertices numbered from 0 to n-1 such that it’s root is vertex numbered 0. Also, each vertex is assigned an integer x (such that value[i]=x). Now you are given q queries such that each query consists of a vertex number. For each query you need to answer the following (let the vertex given in a query be v): Let us consider the path from root of the tree to vertex

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.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start