2492. Minimum Score of a Path Between Two Cities Medium

@problem@discussion



1/**
2 * [2492] Minimum Score of a Path Between Two Cities
3 *
4 * You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei] indicates that there is a bidirectional road between cities ai and bi with a distance equal to distancei. The cities graph is not necessarily connected.
5 * The score of a path between two cities is defined as the minimum distance of a road in this path.
6 * Return the minimum possible score of a path between cities 1 and n.
7 * Note:
8 * 
9 * 	A path is a sequence of roads between two cities.
10 * 	It is allowed for a path to contain the same road multiple times, and you can visit cities 1 and n multiple times along the path.
11 * 	The test cases are generated such that there is at least one path between 1 and n.
12 * 
13 *  
14 * <strong class="example">Example 1:
15 * <img alt="" src="https://assets.leetcode.com/uploads/2022/10/12/graph11.png" style="width: 190px; height: 231px;" />
16 * Input: n = 4, roads = [[1,2,9],[2,3,6],[2,4,5],[1,4,7]]
17 * Output: 5
18 * Explanation: The path from city 1 to 4 with the minimum score is: 1 -> 2 -> 4. The score of this path is min(9,5) = 5.
19 * It can be shown that no other path has less score.
20 * 
21 * <strong class="example">Example 2:
22 * <img alt="" src="https://assets.leetcode.com/uploads/2022/10/12/graph22.png" style="width: 190px; height: 231px;" />
23 * Input: n = 4, roads = [[1,2,2],[1,3,4],[3,4,7]]
24 * Output: 2
25 * Explanation: The path from city 1 to 4 with the minimum score is: 1 -> 2 -> 1 -> 3 -> 4. The score of this path is min(2,2,4,7) = 2.
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	2 <= n <= 10^5
31 * 	1 <= roads.length <= 10^5
32 * 	roads[i].length == 3
33 * 	1 <= ai, bi <= n
34 * 	ai != bi
35 * 	1 <= distancei <= 10^4
36 * 	There are no repeated edges.
37 * 	There is at least one path between 1 and n.
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities/
43// discuss: https://leetcode.com/problems/minimum-score-of-a-path-between-two-cities/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn min_score(n: i32, roads: Vec<Vec<i32>>) -> i32 {
49        0
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_2492() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.