Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

J. Judicious Journey
time limit per test
5 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Map data from OpenStreetMap, available under the Open Database License (ODbL).

As you board the train, a song is stuck in your head, about a small-town girl and a city boy, taking the midnight train goin' anywhere. You, alas, are going somewhere. Your stingy employer is sending you to a conference, and will reimburse your travel expenses—or rather, some of them. Under the company's reimbursement policy, only the $$$k$$$ cheapest legs of your journey are paid for; the rest comes out of your own pocket.

The railroad network consists of stations connected by legs, each of which goes from one station to another for some particular price. There may or may not be a leg going the opposite way, and if there is, it might be priced differently. Plan a journey from your home station to the conference station that minimizes what you pay yourself: the total price of all its legs except the $$$k$$$ cheapest (or nothing at all, if the journey has at most $$$k$$$ legs).

Input

The input consists of:

  • One line with three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$2 \leq n \leq 2000$$$, $$$1 \leq m \leq 3000$$$, $$$0 \leq k \leq 3000$$$), the number of stations, the number of legs, and the number of legs that are reimbursed.
  • $$$m$$$ lines, each containing three integers $$$u$$$, $$$v$$$, and $$$w$$$ ($$$0 \leq u, v \lt n$$$, $$$1 \leq w \leq 10^5$$$, $$$u \neq v$$$), a leg from station $$$u$$$ to station $$$v$$$ at cost $$$w$$$.
The stations are numbered from $$$0$$$ to $$$n-1$$$; the journey starts at station $$$0$$$ and ends at station $$$n-1$$$. For any two stations $$$u$$$ and $$$v$$$, there is at most one leg from $$$u$$$ to $$$v$$$, and it is guaranteed that station $$$n-1$$$ can be reached from station $$$0$$$.
Output

Output the minimum amount you have to pay yourself for a journey from station $$$0$$$ to station $$$n-1$$$.

Examples
Input
4 3 1
0 1 12
1 2 11
2 3 30
Output
42
Input
6 6 1
0 1 1
1 2 4
2 5 4
0 3 3
3 4 3
4 5 4
Output
7
Input
7 9 2
0 1 7
0 2 3
1 2 5
1 3 1
3 4 3
1 4 4
2 5 2
5 4 9
4 6 8
Output
8
Input
7 9 1
0 1 7
0 2 3
1 2 5
1 3 1
3 4 3
1 4 4
2 5 2
5 4 9
4 6 8
Output
15