#3559
Number of Ways to Assign Edge Weights II
expert · 1205 · lc hard +32 · 59.5% accepted · 57 likes · top 57%
Description
A tree with n nodes rooted at 1 is given via edges[i] = [ui, vi]. Assign each edge weight 1 or 2.
For each query [ui, vi], count the weight assignments (restricted to edges on the ui-to-vi path) that make the path total weight odd.
Return array answer with each result modulo 109 + 7, ignoring off-path edges.
Code
1
2
3