You are given an undirected weighted tree, in which 1 is the root node. Control value of each node denoted by ci.
Let's take two nodes (V,U ) such that V is the ancestor of U. V controls U if the distance between U and V is less than or equal to the control value of U
Find the number of vertices controlled by each node.
Task:
Print N integers — the i-th of these numbers should be equal to the number of vertices that the i-th vertex controls.
Note
Example:
Assumptions
Approach
Thus, answer is {2,0,0}
Function Description :
Complete the solve function provided in the editor. This function takes the following 4 parameters and returns the required answer:-
The function must return -
Input format
Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).
Output format
Constraints
1≤N≤2∗105
1≤ci≤109
1≤pi≤N
1≤wi≤109
Code snippets (also called starter code/boilerplate code)
This question has code snippets for C, CPP, Java, and Python.
Given
Approach
Thus, answer is {1,0,0}