← All problemsSign in

Tree Destruction

CodeChefRating 3656Open on judge ↗

Chef is playing the game *Tree Destruction* on his computer, and his goal is to destroy trees. A tree of size $X$ is a connected, acyclic graph with $X$ nodes. The game works as follows: * Initially, Chef's score is $0$. * Chef's goal is to remove all the nodes from the tree while maximizing his score. * At any time, Chef can remove any node with exactly one neighbour in the remaining tree. * By

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