Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0d81bd2

Browse files
authored
Improved task 2846
1 parent7cf0adb commit0d81bd2

File tree

1 file changed

+13
-3
lines changed
  • src/main/java/g2801_2900/s2846_minimum_edge_weight_equilibrium_queries_in_a_tree

1 file changed

+13
-3
lines changed

‎src/main/java/g2801_2900/s2846_minimum_edge_weight_equilibrium_queries_in_a_tree/readme.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ Return _an array_ `answer` _of length_ `m` _where_ `answer[i]` _is the answer to
2121

2222
**Output:**[0,0,1,3]
2323

24-
**Explanation:** In the first query, all the edges in the path from 0 to 3 have a weight of 1. Hence, the answer is 0. In the second query, all the edges in the path from 3 to 6 have a weight of 2. Hence, the answer is 0. In the third query, we change the weight of edge[2,3] to 2. After this operation, all the edges in the path from 2 to 6 have a weight of 2. Hence, the answer is 1. In the fourth query, we change the weights of edges[0,1],[1,2] and[2,3] to 2. After these operations, all the edges in the path from 0 to 6 have a weight of 2. Hence, the answer is 3. For each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from a<sub>i</sub> to b<sub>i</sub>.
24+
**Explanation:** In the first query, all the edges in the path from 0 to 3 have a weight of 1. Hence, the answer is 0.
25+
26+
In the second query, all the edges in the path from 3 to 6 have a weight of 2. Hence, the answer is 0. In the third query, we change the weight of edge[2,3] to 2. After this operation, all the edges in the path from 2 to 6 have a weight of 2. Hence, the answer is 1.
27+
28+
In the fourth query, we change the weights of edges[0,1],[1,2] and[2,3] to 2. After these operations, all the edges in the path from 0 to 6 have a weight of 2. Hence, the answer is 3. For each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from a<sub>i</sub> to b<sub>i</sub>.
2529

2630
**Example 2:**
2731

@@ -31,7 +35,13 @@ Return _an array_ `answer` _of length_ `m` _where_ `answer[i]` _is the answer to
3135

3236
**Output:**[1,2,2,3]
3337

34-
**Explanation:** In the first query, we change the weight of edge[1,3] to 6. After this operation, all the edges in the path from 4 to 6 have a weight of 6. Hence, the answer is 1. In the second query, we change the weight of edges[0,3] and[3,1] to 6. After these operations, all the edges in the path from 0 to 4 have a weight of 6. Hence, the answer is 2. In the third query, we change the weight of edges[1,3] and[5,2] to 6. After these operations, all the edges in the path from 6 to 5 have a weight of 6. Hence, the answer is 2. In the fourth query, we change the weights of edges[0,7],[0,3] and[1,3] to 6. After these operations, all the edges in the path from 7 to 4 have a weight of 6. Hence, the answer is 3. For each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from a<sub>i</sub> to b<sub>i</sub>.
38+
**Explanation:** In the first query, we change the weight of edge[1,3] to 6. After this operation, all the edges in the path from 4 to 6 have a weight of 6. Hence, the answer is 1.
39+
40+
In the second query, we change the weight of edges[0,3] and[3,1] to 6. After these operations, all the edges in the path from 0 to 4 have a weight of 6. Hence, the answer is 2.
41+
42+
In the third query, we change the weight of edges[1,3] and[5,2] to 6. After these operations, all the edges in the path from 6 to 5 have a weight of 6. Hence, the answer is 2.
43+
44+
In the fourth query, we change the weights of edges[0,7],[0,3] and[1,3] to 6. After these operations, all the edges in the path from 7 to 4 have a weight of 6. Hence, the answer is 3. For each queries[i], it can be shown that answer[i] is the minimum number of operations needed to equalize all the edge weights in the path from a<sub>i</sub> to b<sub>i</sub>.
3545

3646
**Constraints:**
3747

@@ -43,4 +53,4 @@ Return _an array_ `answer` _of length_ `m` _where_ `answer[i]` _is the answer to
4353
* The input is generated such that`edges` represents a valid tree.
4454
* <code>1 <= queries.length == m <= 2 * 10<sup>4</sup></code>
4555
*`queries[i].length == 2`
46-
* <code>0 <= a<sub>i</sub>, b<sub>i</sub> < n</code>
56+
* <code>0 <= a<sub>i</sub>, b<sub>i</sub> < n</code>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp