#P2829. 大逃离

大逃离

Description

This is a graph with nn nodes and mm undirected edges. Each edge has a length of ww units. zrz is at position 11, and the exit is at position nn.

However, zrz’s brain has a little bug: he does not want the shortest path; he wants the second-shortest path. The second-shortest path may share edges with the shortest path and may pass through some nodes and edges multiple times. Note that if there are multiple paths that are all shortest, none of them can be called the second-shortest path.

In addition, if the next node to enter has fewer than kk directly connected neighbors (excluding the start and the exit), then zrz will not dare to enter it.

Input Format

The first line contains three numbers: n,m,kn, m, k.

The next mm lines each contain three numbers u,v,wu, v, w, indicating there is an undirected edge of weight ww between uu and vv.

Output Format

Output a single number: the length of the second-shortest path from 11 to nn. If it does not exist, output 1-1.

4 4 1
1 2 100
2 4 200
2 3 250
3 4 100
450
4 4 3
1 2 100
2 4 200
2 3 250
3 4 100
500

Hint

Constraints:

  • For 50%50\% of the testdata: n10n \leq 10, m10m \leq 10.
  • For 90%90\% of the testdata: n1000n \leq 1000, m20000m \leq 20000.
  • For 100%100\% of the testdata: 1n50001 \leq n \leq 5000, 1m1000001 \leq m \leq 100000, 1u,vn1 \leq u, v \leq n, 1w100001 \leq w \leq 10000.

Also, kk is relatively small.

In Sample 22, the shortest path is 300300 (1-2-4). Because it is impossible to go from 22 to 33 (33 is connected to only 22 nodes), it is allowed to go 1-2-1-2-4, and the second-shortest path is 500500.

Translated by ChatGPT 5