#P6029. [JSOI2010] 旅行

[JSOI2010] 旅行

Description

WJJ likes traveling. This time, she plans to visit a valley that is said to have many beautiful waterfalls.

WJJ has obtained a map in advance. The map marks NN habitats of small animals, that is, small villages. Village 11 is where WJJ currently lives, and village NN is where WJJ plans to go.

There are MM bidirectional roads connecting these villages. The ii-th bidirectional road directly connects two villages AiA_i and BiB_i, with length CiC_i. Some roads are tunnels, and some are plank bridges. Roads that seem to cross outside villages on the map do not actually intersect. In other words, if we view the villages and bidirectional roads as a graph in graph theory, we do not guarantee that it is a planar graph, nor do we guarantee that there are no multiple edges. However, one thing is guaranteed: WJJ has carefully verified that she can definitely travel from the village she lives in to the valley she wants to go to.

In WJJ’s magical world, each small animal can use a cactus to cast magic. One of the spells is to swap the lengths of any two bidirectional roads in the world, while keeping the lengths of all other roads unchanged. With WJJ’s current magic level, she can use this road-length swapping spell at most KK times. Unfortunately, since cacti have many thorns, WJJ does not plan to carry one during her trip, so she will finish all planned road swaps at home before setting out.

Assume that during WJJ’s trip, no other animals will swap roads to ruin her planned route. To reach the destination as quickly as possible, WJJ wants the total distance she needs to travel to be as short as possible. That is, after using the spell at most KK times, what is the shortest distance from village 11 to village NN?

Input Format

The first line contains 33 integers N,M,KN, M, K separated by spaces.

The next MM lines each contain 33 integers separated by spaces, representing Ai,Bi,CiA_i, B_i, C_i.

Output Format

Output one integer, the shortest distance between village 11 and village NN after using the spell at most KK times.

5 5 2
1 2 10
2 5 10
1 3 4
3 4 2
4 5 1
3

Hint

Sample Explanation

One feasible plan is to swap the lengths of edge 11 and edge 44, and then swap the lengths of edge 22 and edge 55. After swapping, the shortest path is 1251\rightarrow 2\rightarrow 5, with length 33. It can be proven that there is no better plan.

Constraints

For 100%100\% of the testdata, 1N501\leq N\leq 50, 1M1501\leq M\leq 150, 1K201\leq K\leq 20, 1Ai,BiN1\leq A_i,B_i\leq N, AiBiA_i\neq B_i, 1Ci10001\leq C_i\leq 1000.

Translated by ChatGPT 5