← All problemsSign in

Adi and the Tree

Adi's town has the shape of an undirected tree (i.e. a connected acyclic graph) with $N$ vertices numbered $1$ through $N$. There is one house at each vertex. Initially, all houses have lights turned off. Over time, $M$ events occur. In each event, there are two vertices $a$ and $b$ ($a \neq b$) such that the states of the lights of the houses at vertices $a$ and $b$ get flipped, i.e. at each of

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