You are given an integer array vals of length par of length par[0] == -1, and for each node i where par[i] represents the parent of node i. Each node i is assigned the value vals[i].
For each node i, consider the subtree rooted at node i. A subset of nodes from this subtree is called good if each decimal digit from
The score of a good subset is the sum of the values of the nodes in that subset. The score of an empty subset is
Let maxScore[i] be the maximum score among all good subsets chosen from the subtree rooted at node i.
Return the sum of maxScore[i] across all nodes i from
Constraints:
vals.length
vals[i]
par.length
par[0]
par[i] i in
The input is generated such that the parent array par represents a valid tree.
You are given an integer array vals of length par of length par[0] == -1, and for each node i where par[i] represents the parent of node i. Each node i is assigned the value vals[i].
For each node i, consider the subtree rooted at node i. A subset of nodes from this subtree is called good if each decimal digit from
The score of a good subset is the sum of the values of the nodes in that subset. The score of an empty subset is
Let maxScore[i] be the maximum score among all good subsets chosen from the subtree rooted at node i.
Return the sum of maxScore[i] across all nodes i from
Constraints:
vals.length
vals[i]
par.length
par[0]
par[i] i in
The input is generated such that the parent array par represents a valid tree.