Special Ability
Time limit2sMemory limit512 MB
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 vertices and edges. The vertices are numbered 1 to , 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 . 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 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 . The walk may pass through vertex earlier and come back to it later, and it may finish at vertex with unused uses of the ability left.
Input
The first line contains the number of vertices , the number of edges , and the largest number of times the special ability can be used, . (, , )
Each of the next lines describes one edge with the start vertex , the end vertex , and the weight , separated by spaces. The edge can only be crossed in the direction from to . (, )
Vertex is always reachable from vertex 1 in the given graph.
Output
Print the minimum cost of moving from vertex 1 to vertex on the first line.