#P1396. 营救

    ID: 390 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>图论二分并查集福建省历届夏令营最短路生成树

营救

Description

When Mom came home from work, the neighbors said that Xiaoming had been forced into a police car by a group of strangers. With her experience, she inferred that Xiaoming was taken to district tt, while she herself is in district ss.

The city has mm avenues connecting nn districts. Each avenue connects two districts and has a congestion level. Although Xiaoming’s mom is in a hurry, she does not want the crowded flow to disrupt her elegant pace. Please help her plan a route from ss to tt such that the maximum congestion level among the avenues on the route is minimized.

Input Format

The first line contains four space-separated integers nn, mm, ss, tt, whose meanings are as described above.

The next mm lines each contain three integers u,v,wu, v, w, indicating there is an avenue connecting districts uu and vv with congestion level ww.

There may be multiple avenues between two districts.

Output Format

Output a single integer: the minimal possible value of the maximum congestion level along the chosen route.

3 3 1 3
1 2 2
2 3 1
1 3 3
2

Hint

Constraints

  • For 30%30\% of the testdata, n10n \leq 10.
  • For 60%60\% of the testdata, n100n \leq 100.
  • For 100%100\% of the testdata, 1n1041 \leq n \leq 10^4, 1m2×1041 \leq m \leq 2 \times 10^4, w104w \leq 10^4, 1s,tn1 \leq s, t \leq n. It is guaranteed that from ss one can reach district tt.

Explanation for Sample 1

Xiaoming’s mom needs to go from point 1 to point 3. An optimal route is 1 -> 2 -> 3.

Translated by ChatGPT 5