Efficient Solution for “Number of Ways to Assign Edge Weights I” on LeetCode
Problem Summary
You are given a tree with n nodes rooted at node 1, and each edge initially has a weight of 0. The task is to assign each edge a weight of either 1 or 2. The cost of a path is defined as the sum of edge weights along the path.
Use the...