This page is still under construction.

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

Special Ability

Time limit2sMemory limit512 MB

Summary
Find the minimum cost walk from vertex 1 to N in a directed weighted graph, where the ability can negate the weight of at most C edge crossings.
Level

Hard8 of 10

Topics
Graph, Shortest path, Dynamic programming
Solved
No attempts yet

Problem

There is a directed graph with NN vertices and MM edges. The vertices are numbered 1 to NN, and every edge has a weight. Two vertices can be joined by more than one edge, and an edge can start and end at the same vertex.

Seongwon starts on vertex 1. Every time he crosses an edge he pays the weight of that edge. He may cross the same edge as many times as he wants.

Seongwon has a special ability. At the moment he crosses an edge he may use the ability, and then that crossing costs the weight multiplied by −1-1. The edge returns to its original weight right after the crossing, so crossing it again without the ability costs the original weight. He may use the ability at most CC times over the whole walk.

Write a program that finds the smallest total cost of a walk that starts at vertex 1 and finishes at vertex NN. The walk may pass through vertex NN earlier and come back to it later, and it may finish at vertex NN with unused uses of the ability left.

Input

The first line contains the number of vertices NN, the number of edges MM, and the largest number of times the special ability can be used, CC. (1≤N≤501 \le N \le 50, 1≤M≤25001 \le M \le 2500, 0≤C≤10000 \le C \le 1000)

Each of the next MM lines describes one edge with the start vertex uu, the end vertex vv, and the weight ww, separated by spaces. The edge can only be crossed in the direction from uu to vv. (1≤u,v≤N1 \le u, v \le N, 0≤w≤1000000 \le w \le 100000)

Vertex NN is always reachable from vertex 1 in the given graph.

Output

Print the minimum cost of moving from vertex 1 to vertex NN on the first line.

Examples4

  1. Example 1

    Input
    3 6 1
    1 2 1
    1 3 5
    2 1 1
    2 3 10
    3 1 1
    3 2 1
    
    Expected output
    -9
    
  2. Example 2

    Input
    1 1 1000
    1 1 100
    
    Expected output
    -100000
    
  3. Example 3

    Input
    2 3 2
    1 2 6
    1 2 1
    2 1 4
    
    Expected output
    -9
    
  4. Example 4

    Input
    2 1 100
    1 2 1000
    
    Expected output
    -1000