#P4822. [BJWC2012] 冻结
[BJWC2012] 冻结
Description
Let us consider the simplest travel problem: there are cities and bidirectional roads on this continent. The cities are numbered from to . We start at city and need to reach city . How can we arrive as fast as possible?
Is this not just the shortest path problem? We all know it can be solved using algorithms such as Dijkstra, Bellman-Ford, and Floyd-Warshall.
Now, we have SpellCards that can slow down time by . That is, when traveling along an edge, we may choose to use one card, so the time to pass that road becomes half of the original. Note that:
- On each road, at most one SpellCard can be used.
- Using one SpellCard only takes effect on one road.
- You do not have to use all SpellCards.
Given the above information, your task is to find the minimum time needed to travel from city to city when you may use at most time-slowing SpellCards.
Input Format
The first line contains three integers: , , .
The next lines each contain three integers: , , , meaning there is a bidirectional road between and . Without using a SpellCard, passing through it takes time.
Output Format
Output one integer, the minimum time needed to travel from city to city .
4 4 1
1 2 4
4 2 6
1 3 8
3 4 8
7
Hint
Sample 1 Explanation
Without using any SpellCard, the shortest path is , with total time . Now we can use SpellCard, so we halve the time on the road , and the total time becomes .
Constraints
For of the testdata, it is guaranteed that:
- , .
- , .
- To ensure the answer is an integer, all are even.
- The undirected graph in all data has no self-loops or multiple edges, and is connected.
Translated by ChatGPT 5
京公网安备 11011102002149号