You are given a rooted tree with N nodes (numbered 1 through N); node 1 is the root. Each node has a value; let's denote the value of node i by Ai.


You may perform the following operation any number of times (including zero): choose any node which still exists in the tree and remove the whole subtree of this node including itself.


Let's define the profit as the sum of values of all nodes which currently exist in the tree minus X⋅k, where k denotes the number of times this operation was performed. Find the maximum possible profit.



#i need the code in c program or puthon 3.6

Answers & Comments


Add an Answer


Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Helpful Social

Copyright © 2024 EHUB.TIPS team's - All rights reserved.