Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Note that if a node u contains an apple then all edges in the path from the root to the node u have to be used forward and backward (2 times).
Therefore use a depth-first search (DFS) to check if an edge will be used or not.