👩💻 Join our community of thousands of amazing developers!

2378. Choose Edges to Maximize Score in a Tree 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] = [pari, weighti] indicates that node pari is the parent of node i, and the edge between them has a weight equal to weighti. Since the root does 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 o...