You're given an undirected tree with n nodes labeled from 1 to n, rooted at node 1. The tree structure is defined by a 2D array edges where edges[i] = [u_i, v_i] represents an edge between nodes u_i and v_i.
Initially, all edges have weight 0. Your task is to assign each edge a weight of either 1 or 2. The cost of a path between any two nodes is the sum of all edge weights along that path.
Given a 2D array queries where queries[i] = [u_i, v_i], for each query you need to determine: How many ways can you assign weights (1 or 2) to edges in the path between nodes u_i and v_i such that the total path cost is odd?
Important: For each query, only consider edges that are part of the path between the two query nodes. Return results modulo 10^9 + 7.
Input & Output
Constraints
- 2 โค n โค 104
- edges.length = n - 1
- 1 โค ui, vi โค n
- 1 โค queries.length โค 104
- The given edges form a valid tree