Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use dynamic programming to recursively solve the problem for smaller subtrees.
You can ignore the edges with negative weights.
The states of the dp are the following: the root of the subtree you are at, and a boolean variable that will tell you if you have chosen the edge that connects that node and its parent.
What are the transitions of this dp?