Initially we need to find the amount of coins on each node of the given tree. To do this, initially insert all the leaf nodes in a queue. The amount of coins in these nodes are zero. Now run a normal BFS with this queue. After the BFS you will get an array with the amount of coins on each node of the tree.

Rest of the work is quite straight forward. 3PO and Darth Vader will chose nodes greedily(will always take the node which is not taken by anyone before and with lowest coins among all the available nodes).

80%
Solution Ratio

fsshakkhorEarliest,

shakil07Fastest, 0.0s

Mestu_PaulLightest, 7.3 kB

MR.Jukerburg11Shortest, 750B

Toph uses cookies. By continuing you agree to our Cookie Policy.