#Q76. 「一本通 3.2 例 3」架设电话线
「一本通 3.2 例 3」架设电话线
Description
Original source: USACO 2008 Jan. Silver
In the suburbs, there are communication base stations and bidirectional cables, where the -th cable connects base stations and . Notably, base station is the main station of the communication company, and base station is located on a farm. Now, the farm owner wishes to upgrade the communication lines, where upgrading the -th cable costs .
The telephone company is running a promotional offer. The farm owner can specify a path from base station to base station and designate up to cables on this path to be upgraded for free by the telephone company. The farm owner only needs to pay for the cost of the most expensive remaining cable on the path after the free upgrades. Determine the minimum amount of money required to complete the upgrade.
In one sentence On a weighted undirected graph, find a path from node to node such that the -th largest edge weight on the path is as small as possible.
Input Format
The first line contains three integers .
The next lines each contain three integers .
Output Format
If there is no path from to , output -1. Otherwise, output the minimum required cost.
Sample 1
5 7 1
1 2 5
3 1 4
2 4 8
3 2 3
5 2 9
3 4 7
4 5 6
4
Constraints & Hints