Company: BNY_mellon
Difficulty: medium
Remove Leaves to Create Special Tree Problem Description The country of Hackerland is a tree of tree_nodes nodes labelled 1 to tree_nodes , rooted at node 1 . The i -th edge joins tree_from[i] and tree_to[i] and has weight tree_weight[i] . Node i carries the value arr[i - 1] . distance(x, z) is the sum of the weights of the edges on the path between x and z . The tree is special when its root satisfies the distance test: for every node z of the tree, arr[z - 1] >= distance(1, z) . A leaf is a node joined to the rest of the tree by exactly one edge. One operation removes one leaf. The root is never removed. Report the minimum number of removals that make the tree special. Input Format The first line contains tree_nodes . The second line contains tree_nodes space-separated integers, the array arr . The third line contains tree_edges , followed by a line with the tree_edges values of tree_from . The next line repeats tree_edges , followed by a line with the values of tree_to . The next