#P1674. [USACO05FEB] Secret Milking Machine G

[USACO05FEB] Secret Milking Machine G

Description

John is building a new milking machine, but he does not want others to know. He wants to keep this secret for as long as possible. He hides the machine somewhere on his farm so it will not be found.

During the manufacturing process, he needs to go to the machine’s location TT times. His farm has secret tunnels, but John uses them only on the return trip. The farm is divided into NN regions, labeled from 11 to NN. These regions are connected by PP roads, each road has a length LL less than 10610^6. There may be multiple roads between two regions. To reduce the chance of being discovered, John will not traverse any road on the farm more than once. Of course, he wants the routes to be as short as possible.

Please help John find TT routes from the warehouse to the milking machine’s location. The warehouse is region 11, and the milking machine is at region NN. We ask for the minimal possible value of the length of the longest road among all the roads John will traverse, subject to the condition that no road is reused.

Note that we are not minimizing the total route length. We are minimizing the maximum length among the roads that directly connect two regions (i.e., edges). The testdata guarantees that John can find TT routes from the warehouse to region NN without reusing any road.

Input Format

The first line contains 33 integers NN, PP, and TT, separated by spaces.

Lines 22 to P+1P+1: each line contains 33 integers AiA_i, BiB_i, and LiL_i, indicating there is a road between regions AiA_i and BiB_i with length LiL_i.

Output Format

Output a single line containing one integer: the minimal possible value of the longest road’s length among those John traverses.

7 9 2
1 2 2
2 3 5
3 7 5
1 4 1
4 3 1
4 5 7
5 7 1
1 6 3
6 7 3
5

Hint

Choose routes 12371-2-3-7 and 1671-6-7. The minimal possible value of the longest road among these routes is 55.

For 100%100\% of the testdata: 2N2002 \le N \le 200, 1P4×1041 \le P \le 4 \times 10^4, 1T2001 \le T \le 200, and each road length 106\le 10^6.

Translated by ChatGPT 5