Question: You are given a tree ( a connected, undirected graph with no cycles ) consisting of n nodes numbered from 0 to n - 1

You are given a tree(a connected, undirected graph with no cycles) consisting of n nodes numbered from 0 to n-1 and also an array weight of length n such that weight[i] represents the weight of ith node. You are also given 2d integer ar
ray edges where edges[i]=[X,y] means there exists an undirected edge between x and y. For each pair (i,j) of node you have to sum the weight of node with the minimum value that occurs in the simple path between i and j. For example from node 1 to Lode 5 there exists node with weight 2 in the path between the node 1 and node 5 and this weight is minimum so we have to add this value in our result so finally we sum the minimum weights of node that occurs in path for each pair of nodes and return that value.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!