Question: You are given a tree rooted at node 1 with N nodes. Each node i has a value C [ i - 1 ] .

You are given a tree rooted at node 1 with N nodes. Each node i has a value C[i-1].
You need to choose a subset of nodes that satisfies the following conditions:
1. For any two nodes u, v of the chosen subset, if node w is a common ancestor for u and v, then dist(u,w)!= dist(v,w)
2. For any two nodes u, v of the chosen subset where dist(u,root) dist(v,root)-1, then parent[v]!= u.
The value of the subset is the sum of the values of the chosen nodes.
Find the maximum possible value of a chosen subset. Since the answer may be large return it modulo 10^9+7.

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!