You are given an integer array parent representing a rooted tree with parent[i] is the parent of node i. The root of the tree is node parent[0] == nums of length nums[i] represents the value assigned to node i.
The depth of a node is the number of nodes on the path from the root node
Let i with depth
The weighted sum of the tree is the sum of nums[i]
Constraints:
parent.length == nums.length == n
parent[0] == -1
parent[i] parent represents a valid rooted tree
nums[i]
You are given an integer array parent representing a rooted tree with parent[i] is the parent of node i. The root of the tree is node parent[0] == nums of length nums[i] represents the value assigned to node i.
The depth of a node is the number of nodes on the path from the root node
Let i with depth
The weighted sum of the tree is the sum of nums[i]
Constraints:
parent.length == nums.length == n
parent[0] == -1
parent[i] parent represents a valid rooted tree
nums[i]