#P1948. [USACO08JAN] Telephone Lines S

    ID: 895 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>搜索图论2008二分USACONOI 导刊广度优先搜索,BFS

[USACO08JAN] Telephone Lines S

Description

Years later, Benben (pinyin) grew up to become a telephone line installer. An earthquake destroyed all the city's telephone lines, and Benben is responsible for connecting the city at the epicenter. Around the city there are nn (1n1031 \le n \le 10^3) abandoned telephone poles labeled 11 through nn. There are no existing lines between any pair of poles. In total, there are pp (1p1041 \le p \le 10^4) pairs of poles that can be connected; all other pairs cannot be connected due to the earthquake.

For the ii-th connectable pair, the endpoints are ai,bia_i, b_i, and the distance (line length) is lil_i (1li1061 \le l_i \le 10^6). Each pair (ai,bi)(a_i, b_i) appears at most once in the data. Pole 11 is already connected to the national telephone network, and the entire city's network is concentrated at pole nn. In other words, Benben only needs to find a path that connects pole 11 to pole nn; the other poles do not need to be connected to the network.

The telecom company will support the disaster area by connecting up to kk (1kp1 \le k \le p) pairs of poles designated by Benben for free. For any additional lines used on the chosen path, payment is required, and the total cost is determined by the longest length among those paid lines (each line connects exactly one pair of poles). If the chosen path uses at most kk lines, then the total cost is 00.

Please compute the minimum amount of money needed to connect the city at the epicenter.

Input Format

The first line contains three integers n,p,kn, p, k.

Each of the next pp lines contains three integers ai,bi,lia_i, b_i, l_i.

Output Format

Output a single integer: the minimum total cost of the project. If it is impossible to complete, output 1-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

Hint

Translated by ChatGPT 5