#P15441. [蓝桥杯 2025 国 Python/Java 研究生组] 耗时最短的路径
[蓝桥杯 2025 国 Python/Java 研究生组] 耗时最短的路径
Problem Description
An explorer needs to pass through a maze full of spacetime rifts. There are spacetime rifts (called nodes), numbered . The explorer may stay at any node for any length of time.
There are paths between the rifts. Each path is described by , meaning there is an undirected path between node and node . Traversing this path takes time , and the explorer can enter and traverse it only when the current time is within the interval (therefore, after traversing this path, the arrival time at must be within ).
At the same time, the explorer has a chance to adjust the flow of time: when traversing some path, they may ignore the time restriction . This skill can be used at most times.
Initially, the explorer is at node at time . What is the minimum time needed to reach node from node ?
Input Format
The first line contains three integers , separated by one space.
The next lines each contain five integers , separated by one space, describing the -th path. The graph may contain multiple edges and self-loops.
Output Format
Output one line containing one integer, the answer. If there is no possible path, output .
3 3 0
1 2 1 0 3
2 3 3 5 10
1 3 6 0 7
6
3 3 1
1 2 1 0 3
2 3 3 5 10
1 3 6 0 7
4
Hint
Sample Explanation
For Sample 1: You can directly take the path , which takes 6 units of time. Taking takes 8 units of time, because after reaching node 2 you need to wait until time 5 to continue.
For Sample 2: Since you have one chance to use the skill, first take , then use the skill once on , for a total time of 4.
Constraints and Conventions
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For of the testdata, .
For all testdata, , $1 \le m \le \min\left(\dfrac{n(n-1)}{2}, 10^5\right)$, , , .
Translated by ChatGPT 5