luogu#P6190. [NOI Online #1 入门组] 魔法
[NOI Online #1 入门组] 魔法
Problem Description
Country C consists of cities and directed roads. Both cities and roads are numbered starting from . Traversing road costs .
Now you want to travel from city to city . You may cast magic at most times, so that when you traverse the next road, the cost becomes the opposite of the original, i.e. the cost changes from to . Please compute the minimum total cost needed to finish this trip.
Note: Casting magic only changes the cost for one traversal, and does not change the road’s own . The final total cost may be negative, and a city may be visited multiple times (including city ).
Input Format
The first line contains three integers, representing the number of cities , the number of roads , and the limit on the number of times you can cast magic .
Lines to each contain three integers. On line , the integers indicate that there is a one-way road from to , and traversing it costs .
Output Format
Output one integer in one line, representing the minimum total cost.
4 3 2
1 2 5
2 3 4
3 4 1
-8
2 2 2
1 2 10
2 1 1
-19
Hint
Explanation for Sample Input/Output 1
Traverse road , road , and road in order, and cast magic before traversing roads and .
Explanation for Sample Input/Output 2
Traverse road , road , and road in order, and cast magic before both times you traverse road .
Constraints
This problem has test points. The information for each test point is shown in the table below.
| Test Point ID | Acyclic | |||
|---|---|---|---|---|
| Not guaranteed | ||||
| Yes | ||||
| Not guaranteed | ||||
| Yes | ||||
| Not guaranteed | ||||
For test points where the “Acyclic” column is “Yes”, it is guaranteed that the given graph is a directed acyclic graph; otherwise, there is no guarantee about the graph structure.
For all test points, it is guaranteed that:
- , , .
- , .
- The given graph has no multiple edges or self-loops, and there exists at least one path from to .
**Unofficial testdata is generated within 5 minutes using CYaRon. If you find any issues with the testdata, please post in the discussion board or send a private message to
Translated by ChatGPT 5