← All problemsSign in

O(1) TREE

There is a tree with $N$ vertices. The vertices are numbered 1 through $N$. For each $1≤i≤N−1$, the $i-th$ edge connects vertices $ai$ and $bi$. The lengths of all the edges are 1. Chad likes some of the vertices. The information on his favorite vertices are given to you as a string s of length $N$. For each $1≤i≤N$, si is 1 if Chad likes vertex i, and 0 if he does not like vertex i. Initially, al

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