favorite We need a little bit of your help to keep things running, click on this banner to learn more

2008 USACO January Silver

Telephone Lines

Farmer John wants to set up a telephone line at his farm. Unfortunately, the phone company is uncooperative, so he needs to pay for some of the cables required to connect his farm to the phone system.

There are n forlorn telephone poles conveniently numbered from 1 to n that are scattered around Farmer John's property; no cables connect any them. A total of p pairs of poles can be connected by a cable; the rest are too far apart.

The i-th cable can connect the two distinct poles ai and bi, with length li (1li106) units if used. The input data set never names any {ai, bi} pair more than once. Pole 1 is already connected to the phone system, and pole n is at the farm. Poles 1 and n need to be connected by a path of cables; the rest of the poles might be used or might not be used.

As it turns out, the phone company is willing to provide Farmer John with k lengths of cable for free. Beyond that he will have to pay a price equal to the length of the longest remaining cable he requires (each pair of poles is connected with a separate cable), or 0 if he does not need any additional cables.

Determine the minimum amount that Farmer John must pay.


First line contains three integers n (1n1000), p (1p10000) and k (0k < n). Each of the next p lines contains three integers ai, bi and li.


Print a single integer, the minimum amount Farmer John can pay. If it is impossible to connect the farm to the phone company, print -1.

Time limit 1 second
Memory limit 128 MiB
Input example #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
Output example #1
Source 2008 USACO January Silver