mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-12-19 02:24:59 +08:00
移除零宽空格
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
"boundTopicId": 3677846,
|
||||
"title": "Minimum Weighted Subgraph With the Required Paths II",
|
||||
"titleSlug": "minimum-weighted-subgraph-with-the-required-paths-ii",
|
||||
"content": "<p>You are given an <strong>undirected weighted</strong> tree with <code data-end=\"51\" data-start=\"48\">n</code> nodes, numbered from <code data-end=\"75\" data-start=\"72\">0</code> to <code data-end=\"86\" data-start=\"79\">n - 1</code>. It is represented by a 2D integer array <code data-end=\"129\" data-start=\"122\">edges</code> of length <code data-end=\"147\" data-start=\"140\">n - 1</code>, where <code data-end=\"185\" data-start=\"160\">edges[i] = [u<sub>i</sub>, v<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge between nodes <code data-end=\"236\" data-start=\"232\">u<sub>i</sub></code> and <code data-end=\"245\" data-start=\"241\">v<sub>i</sub></code> with weight <code data-end=\"262\" data-start=\"258\">w<sub>i</sub></code>.</p>\n\n<p>Additionally, you are given a 2D integer array <code data-end=\"56\" data-start=\"47\">queries</code>, where <code data-end=\"105\" data-start=\"69\">queries[j] = [src1<sub>j</sub>, src2<sub>j</sub>, dest<sub>j</sub>]</code>.</p>\n\n<p>Return an array <code data-end=\"24\" data-start=\"16\">answer</code> of length equal to <code data-end=\"60\" data-start=\"44\">queries.length</code>, where <code data-end=\"79\" data-start=\"68\">answer[j]</code> is the <strong>minimum total weight</strong> of a subtree such that it is possible to reach <code data-end=\"174\" data-start=\"167\">dest<sub>j</sub></code> from both <code data-end=\"192\" data-start=\"185\">src1<sub>j</sub></code> and <code data-end=\"204\" data-start=\"197\">src2<sub>j</sub></code> using edges in this subtree.</p>\n\n<p>A <strong data-end=\"2287\" data-start=\"2276\">subtree</strong> here is any connected subset of nodes and edges of the original tree forming a valid tree.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>Input:</strong> <span class=\"example-io\">edges = [[0,1,2],[1,2,3],[1,3,5],[1,4,4],[2,5,6]], queries = [[2,3,4],[0,2,5]]</span></p>\n\n<p><strong>Output:</strong> <span class=\"example-io\">[12,11]</span></p>\n\n<p><strong>Explanation:</strong></p>\n\n<p>The blue edges represent one of the subtrees that yield the optimal answer.</p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2025/04/02/tree1-4.jpg\" style=\"width: 531px; height: 322px;\" /></p>\n\n<ul>\n\t<li data-end=\"118\" data-start=\"0\">\n\t<p data-end=\"118\" data-start=\"2\"><code>answer[0]</code>: The total weight of the selected subtree that ensures a path from <code>src1 = 2</code> and <code>src2 = 3</code> to <code>dest = 4</code> is <code>3 + 5 + 4 = 12</code>.</p>\n\t</li>\n\t<li data-end=\"235\" data-start=\"119\">\n\t<p data-end=\"235\" data-start=\"121\"><code>answer[1]</code>: The total weight of the selected subtree that ensures a path from <code>src1 = 0</code> and <code>src2 = 2</code> to <code>dest = 5</code> is <code>2 + 3 + 6 = 11</code>.</p>\n\t</li>\n</ul>\n</div>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>Input:</strong> <span class=\"example-io\">edges = [[1,0,8],[0,2,7]], queries = [[0,1,2]]</span></p>\n\n<p><strong>Output:</strong> <span class=\"example-io\">[15]</span></p>\n\n<p><strong>Explanation:</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2025/04/02/tree1-5.jpg\" style=\"width: 270px; height: 80px;\" /></p>\n\n<ul>\n\t<li><code>answer[0]</code>: The total weight of the selected subtree that ensures a path from <code>src1 = 0</code> and <code>src2 = 1</code> to <code>dest = 2</code> is <code>8 + 7 = 15</code>.</li>\n</ul>\n</div>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li data-end=\"36\" data-start=\"20\"><code>3 <= n <= 10<sup>5</sup></code></li>\n\t<li data-end=\"62\" data-start=\"39\"><code>edges.length == n - 1</code></li>\n\t<li data-end=\"87\" data-start=\"65\"><code>edges[i].length == 3</code></li>\n\t<li data-end=\"107\" data-start=\"90\"><code>0 <= u<sub>i</sub>, v<sub>i</sub> < n</code></li>\n\t<li data-end=\"127\" data-start=\"110\"><code>1 <= w<sub>i</sub> <= 10<sup>4</sup></code></li>\n\t<li data-end=\"159\" data-start=\"130\"><code>1 <= queries.length <= 10<sup>5</sup></code></li>\n\t<li data-end=\"186\" data-start=\"162\"><code>queries[j].length == 3</code></li>\n\t<li data-end=\"219\" data-start=\"189\"><code>0 <= src1<sub>j</sub>, src2<sub>j</sub>, dest<sub>j</sub> < n</code></li>\n\t<li><code>src1<sub>j</sub></code>, <code>src2<sub>j</sub></code>, and <code>dest<sub>j</sub></code> are pairwise distinct.</li>\n\t<li>The input is generated such that <code>edges</code> represents a valid tree.</li>\n</ul>\n",
|
||||
"content": "<p>You are given an <strong>undirected weighted</strong> tree with <code data-end=\"51\" data-start=\"48\">n</code> nodes, numbered from <code data-end=\"75\" data-start=\"72\">0</code> to <code data-end=\"86\" data-start=\"79\">n - 1</code>. It is represented by a 2D integer array <code data-end=\"129\" data-start=\"122\">edges</code> of length <code data-end=\"147\" data-start=\"140\">n - 1</code>, where <code data-end=\"185\" data-start=\"160\">edges[i] = [u<sub>i</sub>, v<sub>i</sub>, w<sub>i</sub>]</code> indicates that there is an edge between nodes <code data-end=\"236\" data-start=\"232\">u<sub>i</sub></code> and <code data-end=\"245\" data-start=\"241\">v<sub>i</sub></code> with weight <code data-end=\"262\" data-start=\"258\">w<sub>i</sub></code>.</p>\n\n<p>Additionally, you are given a 2D integer array <code data-end=\"56\" data-start=\"47\">queries</code>, where <code data-end=\"105\" data-start=\"69\">queries[j] = [src1<sub>j</sub>, src2<sub>j</sub>, dest<sub>j</sub>]</code>.</p>\n\n<p>Return an array <code data-end=\"24\" data-start=\"16\">answer</code> of length equal to <code data-end=\"60\" data-start=\"44\">queries.length</code>, where <code data-end=\"79\" data-start=\"68\">answer[j]</code> is the <strong>minimum total weight</strong> of a subtree such that it is possible to reach <code data-end=\"174\" data-start=\"167\">dest<sub>j</sub></code> from both <code data-end=\"192\" data-start=\"185\">src1<sub>j</sub></code> and <code data-end=\"204\" data-start=\"197\">src2<sub>j</sub></code> using edges in this subtree.</p>\n\n<p>A <strong data-end=\"2287\" data-start=\"2276\">subtree</strong> here is any connected subset of nodes and edges of the original tree forming a valid tree.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>Input:</strong> <span class=\"example-io\">edges = [[0,1,2],[1,2,3],[1,3,5],[1,4,4],[2,5,6]], queries = [[2,3,4],[0,2,5]]</span></p>\n\n<p><strong>Output:</strong> <span class=\"example-io\">[12,11]</span></p>\n\n<p><strong>Explanation:</strong></p>\n\n<p>The blue edges represent one of the subtrees that yield the optimal answer.</p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2025/04/02/tree1-4.jpg\" style=\"width: 531px; height: 322px;\" /></p>\n\n<ul>\n\t<li data-end=\"118\" data-start=\"0\">\n\t<p data-end=\"118\" data-start=\"2\"><code>answer[0]</code>: The total weight of the selected subtree that ensures a path from <code>src1 = 2</code> and <code>src2 = 3</code> to <code>dest = 4</code> is <code>3 + 5 + 4 = 12</code>.</p>\n\t</li>\n\t<li data-end=\"235\" data-start=\"119\">\n\t<p data-end=\"235\" data-start=\"121\"><code>answer[1]</code>: The total weight of the selected subtree that ensures a path from <code>src1 = 0</code> and <code>src2 = 2</code> to <code>dest = 5</code> is <code>2 + 3 + 6 = 11</code>.</p>\n\t</li>\n</ul>\n</div>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>Input:</strong> <span class=\"example-io\">edges = [[1,0,8],[0,2,7]], queries = [[0,1,2]]</span></p>\n\n<p><strong>Output:</strong> <span class=\"example-io\">[15]</span></p>\n\n<p><strong>Explanation:</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2025/04/02/tree1-5.jpg\" style=\"width: 270px; height: 80px;\" /></p>\n\n<ul>\n\t<li><code>answer[0]</code>: The total weight of the selected subtree that ensures a path from <code>src1 = 0</code> and <code>src2 = 1</code> to <code>dest = 2</code> is <code>8 + 7 = 15</code>.</li>\n</ul>\n</div>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li data-end=\"36\" data-start=\"20\"><code>3 <= n <= 10<sup>5</sup></code></li>\n\t<li data-end=\"62\" data-start=\"39\"><code>edges.length == n - 1</code></li>\n\t<li data-end=\"87\" data-start=\"65\"><code>edges[i].length == 3</code></li>\n\t<li data-end=\"107\" data-start=\"90\"><code>0 <= u<sub>i</sub>, v<sub>i</sub> < n</code></li>\n\t<li data-end=\"127\" data-start=\"110\"><code>1 <= w<sub>i</sub> <= 10<sup>4</sup></code></li>\n\t<li data-end=\"159\" data-start=\"130\"><code>1 <= queries.length <= 10<sup>5</sup></code></li>\n\t<li data-end=\"186\" data-start=\"162\"><code>queries[j].length == 3</code></li>\n\t<li data-end=\"219\" data-start=\"189\"><code>0 <= src1<sub>j</sub>, src2<sub>j</sub>, dest<sub>j</sub> < n</code></li>\n\t<li><code>src1<sub>j</sub></code>, <code>src2<sub>j</sub></code>, and <code>dest<sub>j</sub></code> are pairwise distinct.</li>\n\t<li>The input is generated such that <code>edges</code> represents a valid tree.</li>\n</ul>\n",
|
||||
"translatedTitle": "包含给定路径的最小带权子树 II",
|
||||
"translatedContent": "<p>给你一个 <strong>无向带权 </strong>树,共有 <code>n</code> 个节点,编号从 <code>0</code> 到 <code>n - 1</code>。这棵树由一个二维整数数组 <code>edges</code> 表示,长度为 <code>n - 1</code>,其中 <code>edges[i] = [u<sub>i</sub>, v<sub>i</sub>, w<sub>i</sub>]</code> 表示存在一条连接节点 <code>u<sub>i</sub></code> 和 <code>v<sub>i</sub></code> 的边,权重为 <code>w<sub>i</sub></code>。</p>\n\n<p>此外,给你一个二维整数数组 <code>queries</code>,其中 <code>queries[j] = [src1<sub>j</sub>, src2<sub>j</sub>, dest<sub>j</sub>]</code>。</p>\n\n<p>返回一个长度等于 <code>queries.length</code> 的数组 <code>answer</code>,其中 <code>answer[j]</code> 表示一个子树的 <strong>最小总权重 </strong>,使用该子树的边可以从 <code>src1<sub>j</sub></code> 和 <code>src2<sub>j</sub></code> 到达 <code>dest<sub>j</sub></code><sub> </sub>。</p>\n\n<p>这里的 <strong>子树 </strong>是指原树中任意节点和边组成的连通子集形成的一棵有效树。</p>\n\n<p> </p>\n\n<p><strong class=\"example\">示例 1:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>输入:</strong> <span class=\"example-io\">edges = [[0,1,2],[1,2,3],[1,3,5],[1,4,4],[2,5,6]], queries = [[2,3,4],[0,2,5]]</span></p>\n\n<p><strong>输出:</strong> <span class=\"example-io\">[12,11]</span></p>\n\n<p><strong>解释:</strong></p>\n\n<p>蓝色边表示可以得到最优答案的子树之一。</p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2025/04/02/tree1-4.jpg\" style=\"width: 531px; height: 322px;\" /></p>\n\n<ul>\n\t<li>\n\t<p><code>answer[0]</code>:在选出的子树中,从 <code>src1 = 2</code> 和 <code>src2 = 3</code> 到 <code>dest = 4</code> 的路径总权重为 <code>3 + 5 + 4 = 12</code>。</p>\n\t</li>\n\t<li>\n\t<p><code>answer[1]</code>:在选出的子树中,从 <code>src1 = 0</code> 和 <code>src2 = 2</code> 到 <code>dest = 5</code> 的路径总权重为 <code>2 + 3 + 6 = 11</code>。</p>\n\t</li>\n</ul>\n</div>\n\n<p><strong class=\"example\">示例 2:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>输入:</strong> <span class=\"example-io\">edges = [[1,0,8],[0,2,7]], queries = [[0,1,2]]</span></p>\n\n<p><strong>输出:</strong> <span class=\"example-io\">[15]</span></p>\n\n<p><strong>解释:</strong></p>\n\n<p><img alt=\"\" src=\"https://assets.leetcode.com/uploads/2025/04/02/tree1-5.jpg\" style=\"width: 270px; height: 80px;\" /></p>\n\n<ul>\n\t<li><code>answer[0]</code>:选出的子树中,从 <code>src1 = 0</code> 和 <code>src2 = 1</code> 到 <code>dest = 2</code> 的路径总权重为 <code>8 + 7 = 15</code>。</li>\n</ul>\n</div>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>3 <= n <= 10<sup>5</sup></code></li>\n\t<li><code>edges.length == n - 1</code></li>\n\t<li><code>edges[i].length == 3</code></li>\n\t<li><code>0 <= u<sub>i</sub>, v<sub>i</sub> < n</code></li>\n\t<li><code>1 <= w<sub>i</sub> <= 10<sup>4</sup></code></li>\n\t<li><code>1 <= queries.length <= 10<sup>5</sup></code></li>\n\t<li><code>queries[j].length == 3</code></li>\n\t<li><code>0 <= src1<sub>j</sub>, src2<sub>j</sub>, dest<sub>j</sub> < n</code></li>\n\t<li><code>src1<sub>j</sub></code>、<code>src2<sub>j</sub></code> 和 <code>dest<sub>j</sub></code> 互不不同。</li>\n\t<li>输入数据保证 <code>edges</code> 表示的是一棵有效的树。</li>\n</ul>\n",
|
||||
"isPaidOnly": false,
|
||||
|
||||
Reference in New Issue
Block a user