Practice Maximum Score After Applying Operations on a Tree
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Maximum Score After Applying Operations on a Tree
Problem Statement
The tree with edges and values is rooted at 0. Start with score 0. An operation adds a chosen node value to the score and replaces that value with 0. The tree must remain healthy: every root-to-leaf path has a nonzero sum of node values. Return the greatest score obtainable while preserving that condition.
Source: Maximum Score After Applying Operations on a Tree on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
edges = [[0,1],[0,2],[0,3],[2,4],[4,5]], values = [5,2,5,2,1,1]
11
# Example 2
edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [20,10,9,7,4,3,5]
40
Constraints
Related LeetCode Problems
Practice more problems similar to Maximum Score After Applying Operations on a Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.