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).

75% Solution Ratio

fsshakkhorEarliest,

fragilisticFastest, 0.0s

sarwarITLightest, 6.2 MB

MR.Jukerburg11Shortest, 750B