Company: KFin technologies_26july
Difficulty: medium
Trim A Tree Problem Description A farmer has a tree with N nodes. He wants to trim the tree using an operation T to t-N-s. In one operation he will choose any edge and delete it. From the resulting two connected components(i.e. trees) keep one and discard the other. Additionally, the farmer has an array A which gives the score of each node of a certain degree present in the tree. The farmer wants to apply the operation such that the total score of the tree left is maximum. The total score of the tree left is defined as the sum of values of A as per the degree of each node left in the tree. This means that a node of degree 1 left in the final tree will contribute A[1] to the total score. Find the maximum possible score for the tree left. Notes: A Tree is an undirected connected graph with N vertices and N-1 edge with no loops or multiple edges and the description of the edges in two arrays U and V where there is an edge between node U i and node V i . It is given that the array A follow