Input: N = 6, arr[] = {13, 8, 7, 4, 5, 9}, Edges[][] = {{0, 1}, {1, 2}, {1, 4}, {3, 4}, {4, 5}}
Output: 504
Explanation:
Below is the given tree and resultant tree after removing the edge:

Remove the edge between 1st and 4th, then
t1 = valueat[0] + valueat[1] + valueat[2] = 13 + 8 + 7
t1 = valueat[3] + valueat[4] + valueat[5] = 4 + 5 + 9
t1*t2 = (13 + 8 + 7) * (4 + 5 + 9) = 504
Input: N = 7, arr[]= {13, 8, 7, 4, 5, 9, 100}, Edges[][] = { {0, 1}, {1, 2}, {1, 4}, {3, 4}, {4, 5}, {2, 6}}
Output: 4600
Explanation:
Below is the given tree and resultant tree after removing the edge:

Remove the edge between 2nd and 6th, then
t1 = valueat[0] + valueat[1] + valueat[2] + valueat[3] + valueat[4] + valueat[5]= 13 + 8 + 7 + 4 + 5 + 9
t2 = valueat[6] = 100
t1*t2 = (13 + 8 + 7 + 5 + 4 + 9) * (100) = 4600