Loading...
You are given an integer n and an undirected weighted graph on nodes labeled 1 to n, given as an array edges where each entry is [a, b, w]: an edge between a and b with weight w. The graph may be disconnected, but at least one path between node 1 and node n is guaranteed.
Define the score of a walk from 1 to n as the smallest edge weight on it. Walks may revisit nodes and edges freely.
Return the minimum possible score, equivalently the smallest weight among all edges reachable from node 1 (a walk from 1 to n can always detour through any reachable edge and come back).
Input: n = 4, edges = [[1,2,9],[2,3,6],[2,4,5],[1,4,7]]
Output: 5
Explanation: The walk 1 → 2 → 4 uses edges of weights 9 and 5; its score is 5. No walk can do better.
Input: n = 4, edges = [[1,2,2],[1,3,4],[3,4,7]]
Output: 2
Explanation: The walk 1 → 2 → 1 → 3 → 4 revisits node 1 and picks up the weight-2 edge.
edges.length ≤105edges[i].length == 31 and node n.Click "Run" to test with sample cases or "Submit" to run all tests.