#3558

Number of Ways to Assign Edge Weights I

specialist · 835 · lc medium +31 · 53.2% accepted · 58 likes · top 44%

Description

An unrooted tree with n nodes (rooted at 1) has edges given by edges[i] = [ui, vi]. Assign each edge a weight of 1 or 2.

Choose any deepest node x and count the number of weight assignments for the root-to-x path such that the path\'s total weight is odd.

Return the count modulo 109 + 7, ignoring edges outside the chosen path.

Code

1
2
3