Tap here to switch tabs
Problem
Submissions

Problem: Number of Ways to Assign Edge Weights I

med
30 min
Try to solve the Number of Ways to Assign Edge Weights I problem.

Statement

You are given an undirected tree rooted at node 11 with nn nodes labeled from 11 to nn, represented by a 2extD2 ext{D} integer array edges of length n−1n - 1, where edges[i] = [uiu_i, viv_i] indicates an edge between node uiu_i and node viv_i.

Consider the simple path from root node 11 to any node that is at the maximum depth from node 11. Each edge along this path must be assigned an integer weight of either 11 or 22.

Return the number of ways to assign weights to the edges on this path such that the total sum of the edge weights along the path is odd.

Constraints:

  • 2≤n≤1052 \leq n \leq 10^5

  • edges.length =n−1= n - 1

  • edges[i] = [uiu_i, viv_i]

  • 1≤ui,vi≤n1 \leq u_i, v_i \leq n

  • edges represents a valid tree.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Ways to Assign Edge Weights I

med
30 min
Try to solve the Number of Ways to Assign Edge Weights I problem.

Statement

You are given an undirected tree rooted at node 11 with nn nodes labeled from 11 to nn, represented by a 2extD2 ext{D} integer array edges of length n−1n - 1, where edges[i] = [uiu_i, viv_i] indicates an edge between node uiu_i and node viv_i.

Consider the simple path from root node 11 to any node that is at the maximum depth from node 11. Each edge along this path must be assigned an integer weight of either 11 or 22.

Return the number of ways to assign weights to the edges on this path such that the total sum of the edge weights along the path is odd.

Constraints:

  • 2≤n≤1052 \leq n \leq 10^5

  • edges.length =n−1= n - 1

  • edges[i] = [uiu_i, viv_i]

  • 1≤ui,vi≤n1 \leq u_i, v_i \leq n

  • edges represents a valid tree.