Can anyone teach me DP on trees with the help of solving this question?

I came across this problem (DP on trees):

I solved some beginner level problems on DP but I am not able to get the logic of this particular topic. I tried reading about this topic on the IARCS website (link) but I couldn’t understand it completely. Can anyone explain me DP on trees along with solving the question given above? (I mean, like a proper tutorial. Since there are very few good resources on DP on trees, it would help all of them searching for this topic)

1 Like

DP on Trees should do the trick