← All problemsSign in

Tree destruction

Tarjan and Dijkstra are playing a game. Both of them have a tree each, and each edge of their respective trees has some weight. The trees are both rooted at the node with index 1(1-indexed). The cost of travelling from a node u to a node v is the sum of the weights of the edges on the path between them. The mobilisation cost for a tree is defined as follows. Now, Tarjan and Dijkstra both have

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