Balanced 0-1 Tree
You have a tree of $N$ vertices rooted at vertex $1$, where $N$ is **even**. The $i$-th vertex has a binary value $A_i$ written on it (i.e, each $A_i$ is either $0$ or $1$). A tree is said to be **balanced** if and only if the number of zeros written on its vertices equals the number of ones written on its vertices. You can select some **disjoint** subtrees and flip the values on them (i.e, make
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