🎁 Exclusive Offer! Join our Telegram Channel to get **special discounts** and updates! 🚀

🚀 Struggling with coding interviews? We've got you covered! 💡 Practice real questions, sharpen your skills, and land your dream job! 🎯
Question 16 - 100% Working Solution | Buy Now

Description

9 Live
Efficient Network There are n computer systems connected together to form a network. The network can be represented as a rooted tree (rooted at master computer 1), where the connections are described using two arrays connect_from[]and connect_to[]. Each pair (connect_from[i], connect_to[i]) denotes an undirected edge between the two computers. Additionally, each computer has a value assigned to it denoted by the array computer_val[]. In order to maximize the throughput of the network, certain inefficient systems can be removed. In one operation, any computer node can be chosen, and all computer nodes in its subtree including this node can be removed from the network. Let the number of such operations appfied be num_ops. For a given parameter k, the efficiency of the network after num_ops operations is calculated as: (sum of values of all remaining computer nodes - k * num_ops). Find the maximum possible efficiency after applying some (possibly zero) operations optimally. Note: The node values can be negative. Example Consider the number of computers to be connect_nodes = 4, and their connections to be connect_from = [1, 2, 3], connect_to = [2, 3, 4]. Also, consider the node values to be computer_val = [3, -7, -8, -9] and the given parameter to be k = 5. The given network cĂĽn be represented as:

Asked in: ShareChat

Image of the Question

Question Image Question Image

All Testcases Passed ✔



Passcode Image

Solution


Please login to view the solution