← All problemsSign in

Tokens On A Tree

CodeChefRating 2885Open on judge ↗

You are given a rooted tree with $N$ nodes numbered $1, 2, \ldots, N$. Node $1$ is the root node. Some of the nodes have a token in them. In one move, you can choose a non-root node that has a token, but its parent doesn't, and move the token from this node to its parent. What is the maximum number of moves you can make? **Note:** When a token is moved out of a node, the node becomes empty, and

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