I don’t have any idea till now…but I guess BFS might work… though I’m not sure. I’ll update when I myself get an idea.
1 Like
Well, you’re given that the graph is a DAG (or a tree, either way), so you can do something like this (do DP with topological sort). Were it not a DAG, the problem would be NP-complete.
1 Like
Thank you!
1 Like