Company: Razorpay_12oct
Difficulty: medium
Optimal Candy Collection Problem Description You are given a tree with N nodes and N - 1 edges, rooted at node 1, where every node holds exactly one piece of candy. Let A_i denote the price of the candy sitting at the i-th node. You are carrying K units of money in total. You must choose exactly one node u to start from, and from there you walk up the tree toward the root, buying candy as you go: first the candy at u, then the candy at u's parent, then that node's parent, and so on, stopping only once your money runs out or you reach the root. You are not allowed to skip past a node on this path without buying its candy. Work out the largest number of candies you could end up buying, over all possible choices of the single starting node u. Notes A graph is connected if, for each pair of nodes u and v, there exists a path between these two nodes in the graph. A tree is a connected graph with N nodes and N - 1 edges. Function description Complete the solve function. This function takes t