Given a tree represented by a list of edges, and with each node of the tree having some value associated with it which is given in an array A, find the edge in the tree which, if it were to be cut, would result in the minimum absolute difference in the sums of the two groups of nodes either side of the edge
Example:
The nodes of the tree are 1,2 and 3
Edges: [[1,2],[2,3]]
Array A: [10,5,20]
Here, if we were to cut the tree at edge joining 2 and 3, we will have nodes 1 and 2 on one side with values 10 and 5, and node 3 on the other side with value 20. The absolute difference between the sums of these two groups is abs ((10 + 5) - (20)) = 5 which is miniumum. Hence the answer is edge 2(we need to return the index of the edge, assuming 1-indexing)
Another example:
edges: [[1,2],[1,3],[2,4],[2,5],[3,6],[3,7]]
A: [3,6,5,3,2,3,5]
Answer is: 2 (ie the edge 1,3)
Looks like a DP problem but I completely blanked on this. I dont even know where to get started with this one.