← 返回 walmartlabs 的题目列表Minimum Stress Path in an Undirected Weighted Graph
类型:online_judge
Problem: Minimum Stress Path in an Undirected Weighted Graph
You are given an undirected weighted graph with n nodes and m edges. Nodes are labeled from 0 to n - 1. You are also given a source node start and a destination node end.
For a path from start to end, define its Stress Level as the maximum edge weight along that path.
Return the minimum possible Stress Level among all paths from start to end.
If end is not reachable from start, return -1.
Input Format
n m
u1 v1 w1
u2 v2 w2
...
um vm wm
start end
Each edge (ui, vi, wi) represents an undirected edge between ui and vi with weight wi.
Output Format
Print one integer: the minimum stress level, or -1 if unreachable.
Constraints
1 <= n <= 10^5
0 <= m <= 2 * 10^5
0 <= ui, vi < n
1 <= wi <= 10^9
0 <= start, end < n
Multiple edges may exist between the same pair of nodes.
The graph may be disconnected.
Example 1
Input:
4 4
0 1 4
1 2 3
0 2 5
2 3 6
0 3
Output:
6
Example 2
Input:
5 3
0 1 10
1 2 2
3 4 1
0 4
Output:
-1
Example
Input
4 4
0 1 4
1 2 3
0 2 5
2 3 6
0 3
Output
6