Practice Minimum Weighted Subgraph With the Required Paths II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Minimum Weighted Subgraph With the Required Paths II
Problem Statement
You are given an undirected weighted tree with n nodes, numbered from 0 to n - 1. It is represented by a 2D integer array edges of length n - 1, where edges[i] = [ui, vi, wi] indicates that there is an edge between nodes ui and vi with weight wi. Additionally, you are given a 2D integer array queries, where queries[j] = [src1j, src2j, destj]. Return an array answer of length equal to queries.length, where answer[j] is the minimum total weight of a subtree such that it is possible to reach destj from both src1j and src2j using edges in this subtree. A subtree here is any connected subset of nodes and edges of the original tree forming a valid tree.
Source: Minimum Weighted Subgraph With the Required Paths II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
edges = [[0,1,2],[1,2,3],[1,3,5],[1,4,4],[2,5,6]], queries = [[2,3,4],[0,2,5]]
[12,11]
# Example 2
edges = [[1,0,8],[0,2,7]], queries = [[0,1,2]]
[15]
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Weighted Subgraph With the Required Paths II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.