Question: A tree with N nodes is rooted at node 1 is given to you in the form of an array P . P [ i
A tree with N nodes is rooted at node
is given to you in the form of an array P
P
i
denotes the parent of the ith node. An array A is also given to you, where A
i
represents the number of coins present at the ith node.
you can pick some nodes as long as you follow the rules given below:
You can pick any node at most once.
It is given that among two nodes A and B the one with strictly lesser distance from node
is picked first.
The number of coins at a chosen node is added to your score.
Find the minimum number of nodes that needs to be picked to get a score strictly greater than K
Output
if it is impossible to get a score greater than K
Input format
The first line contains an integer, N
denoting the number of elements in P
The next contains an integer K
denoting the minimum required score,
Each line i of N subsequent lines
where
i
N
contains an integer
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
