This page is still under construction.

Parts of this page are still being built. What you see may change.

Booster

Time limit1sMemory limit128 MB

Summary
Compute how many minutes up to K halve-one-edge boosters save on the fastest route from district 1 to district N.
Level

Medium6 of 10

Topics
Shortest path, Dynamic programming
Solved
No attempts yet

Problem

Bob drives from his house to his office every day. The two are far apart, so he crosses several districts on the way, and he always takes the fastest route on the street map he keeps. One day traffic held him up and he arrived late. His boss put him on probation and told him that arriving late once more costs him the job. Bob has worried about it day and night ever since.

Alice knows the situation, so she built boosters for Bob's car. A booster makes the car run twice as fast, but it shuts off the moment the car turns or slows down. One booster therefore works on exactly one street, and it is used up once Bob has driven that street. Two boosters cannot be spent on the same street. A street that takes TT minutes takes ⌊T/2⌋\lfloor T/2 \rfloor minutes with a booster on it.

Today the traffic is the worst it has ever been. Bob has KK boosters and may use some of them or all of them. His house is district 1 and his office is district NN. Take the shortest travel time with no booster and subtract the shortest travel time Bob can reach when the boosters are placed as well as possible. That difference is how many minutes he saves today.

Input

The first line contains the number of test cases CC.

The first line of each test case holds three integers NN, MM, and KK (1≤N≤5 0001 \le N \le 5\,000, 1≤M≤100 0001 \le M \le 100\,000, 1≤K≤1001 \le K \le 100), the number of districts, the number of streets, and the number of boosters Bob has.

Each of the next MM lines describes one street with three integers XX, YY, and TT (1≤X,Y≤N1 \le X, Y \le N, 2≤T≤100 0002 \le T \le 100\,000). The street connects district XX and district YY, and driving it takes TT minutes. Every street is two way, so Bob may drive it in either direction. No two streets connect the same pair of districts. A route from district 1 to district NN always exists.

Output

Print one line per test case, holding a single integer. It is the largest amount of time Bob can save with at most KK boosters, that is, the shortest travel time without boosters minus the shortest travel time he can reach by placing the boosters.

Examples1

  1. Example 1

    Input
    1
    6 8 1
    1 2 4
    2 3 4
    3 6 5
    1 4 2
    2 4 6
    4 3 12
    4 5 10
    5 6 4
    
    Expected output
    3