Sponsored
Use these hints if you're stuck. Try solving on your own first.
All leaves that do not have a coin are redundant and can be deleted from the tree.
Remove the leaves that do not have coins on them, so that the resulting tree will have a coin on every leaf.
In the remaining tree, remove each leaf node and its parent from the tree. The remaining nodes in the tree are the ones that must be visited. Hence, the answer is equal to (# remaining nodes -1) * 2