I am given a (not necessarily binary) tree with integer (positive/negative) lables on the nodes, and have to find the binary subtree that maximizes the sum of the lables in the tree. I thought about dynamic programming approach - I defined f(u) that returns the maximum sum for all binary trees rooted in u, and calculate f(u) by choosing v,w such that v,w are children of u and they maximze the sum (f(v)+f(w)) over all pairs of u's children, and then f(u) = label(u) + f(v) + f(w). f can be calculated from the leaves up in a typical dynamic programming approach. My question are:
(1) is there a more efficient approach? (2) it seems the most costly step is to find the maximum among all pairs of u's children - if u has n children, the cost is O(n^2), but I think that for entire tree it's less than O(|E|^2), is it true? how can I calculate the cost more tightly?
Thanks.