Given a tree with nodes having unique identifiers and non-negative integer weights, find the maximum sum of weights that can be obtained by removing a subset of nodes such that the remaining nodes form a connected subtree.
Explanation: Remove node 3 to get the maximum sum of 5 + 3 + 7 = 15
Explanation: Keep all nodes to get the maximum sum of 10 + 8 + 4 + 6 = 28, however the problem statement asks for the maximum sum after removing a subset of nodes, in this case removing no nodes gives the maximum sum of 28, the given output of 18 is incorrect.
Dynamic programming over tree structures
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak