← All problemsSign in

Keep Magnets Separated

CodeChefRating 2709Open on judge ↗

There are $N$ magnets on a tree of $N$ nodes numbered $1$ to $N$, one in each node. Upon introducing an external magnet at some node of the tree, all the magnets come closer by $1$ step, while the magnets at that node remains stationary. More formally, suppose we introduced an external magnet at node $x$, then : - Magnets placed at node $x$ will not move. - Magnets placed at any other node $u (

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