Company: Point72_16nov
Difficulty: medium
Tree Value Problem Description Given an unweighted undirected tree with g_nodes nodes rooted at 0, each node has a value specified in array arr. There is also a parameter k. The tree is represented with g_nodes nodes numbered from 0 to g_nodes - 1 and g_edges = g_nodes - 1 edges. The i^th edge connects the nodes numbered g_from[i] to g_to[i]. Each node u has an associated value represented by arr[u]. Collect the values at the nodes using one of two methods: - Collect arr[u] - k points. - Collect floor(arr[u]/2) points. If this method is chosen, all values of node j in this node's subtree are changed to the floor(arr[j]/2) as well. You can only collect the value at a node if its parent's value has been collected before (except the root). You have to maximize the total points collected. Note: It is possible that the accumulated value may be negative at some point. Complete the function treePoints in the editor with the following parameters: - int g_nodes: the number of nodes in the graph