Practice Minimum Edge Weight Equilibrium Queries in a Tree
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Minimum Edge Weight Equilibrium Queries in a Tree
Problem Statement
The n-node tree has edges [u,v,w], with weight w on the undirected edge between u and v. For each query [a,b], find the fewest edge-weight changes needed to make every edge on the path from a to b have the same weight. A change may assign any weight to one edge. Queries are independent: each starts with the original weights. Return answers in query order.
Source: Minimum Edge Weight Equilibrium Queries in a Tree on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
n = 7, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], queries = [[0,3],[3,6],[2,6],[0,6]]
[0,0,1,3]
# Example 2
n = 8, edges = [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], queries = [[4,6],[0,4],[6,5],[7,4]]
[1,2,2,3]
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Edge Weight Equilibrium Queries in a Tree.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.