Company: HPE_3oct
Difficulty: medium
No Ancestor Subset Problem Description Given a tree with tree_nodes nodes, where each node i has an associated weight weight[i] (1-based indexing). The tree is rooted at node 1. A subset of nodes is called "good" if there is no pair of nodes where one node is an ancestor of the other. Find the maximum sum of weights from nodes that form a good subset. Note: A node u is an ancestor of node v if it lies on the direct path from the root to node v . For example, consider the following tree structure and weights: tree_nodes = 3 tree_from = [1, 1] tree_to = [2, 3] weight = [2, 2, 1] Nodes are labeled node:weight. The possible subsets are below. Subset | Is it good? | Sum of weights ----------|-------------|--------------- {1} | Yes | 2 {2} | Yes | 2 {3} | Yes | 1 {1,2} | No | {1,3} | No | {2,3} | Yes | 3 {1,2,3} | No | The maximum sum of weights of nodes forming a good subset is 3. Function Description Complete the function findMaximumSum in the editor with the following parameters: int tree