##### Welcome to Subscribe On Youtube

Formatted question description: https://leetcode.ca/all/2378.html

# 2378. Choose Edges to Maximize Score in a Tree

## Description

You are given a **weighted** tree consisting of `n`

nodes numbered from `0`

to `n - 1`

.

The tree is **rooted** at node `0`

and represented with a **2D** array `edges`

of size `n`

where `edges[i] = [par`

indicates that node _{i}, weight_{i}]`par`

is the _{i}**parent** of node `i`

, and the edge between them has a weight equal to `weight`

. Since the root does _{i}**not** have a parent, you have `edges[0] = [-1, -1]`

.

Choose some edges from the tree such that no two chosen edges are **adjacent** and the **sum** of the weights of the chosen edges is maximized.

Return *the maximum sum of the chosen edges*.

**Note**:

- You are allowed to
**not**choose any edges in the tree, the sum of weights in this case will be`0`

. - Two edges
`Edge`

and_{1}`Edge`

in the tree are_{2}**adjacent**if they have a**common**node.- In other words, they are adjacent if
`Edge`

connects nodes_{1}`a`

and`b`

and`Edge`

connects nodes_{2}`b`

and`c`

.

- In other words, they are adjacent if

**Example 1:**

Input:edges = [[-1,-1],[0,5],[0,10],[2,6],[2,4]]Output:11Explanation:The above diagram shows the edges that we have to choose colored in red. The total score is 5 + 6 = 11. It can be shown that no better score can be obtained.

**Example 2:**

Input:edges = [[-1,-1],[0,5],[0,-6],[0,7]]Output:7Explanation:We choose the edge with weight 7. Note that we cannot choose more than one edge because all edges are adjacent to each other.

**Constraints:**

`n == edges.length`

`1 <= n <= 10`

^{5}`edges[i].length == 2`

`par`

_{0}== weight_{0}== -1`0 <= par`

for all_{i}<= n - 1`i >= 1`

.`par`

_{i}!= i`-10`

for all^{6}<= weight_{i}<= 10^{6}`i >= 1`

.`edges`

represents a valid tree.