#P15441. [蓝桥杯 2025 国 Python/Java 研究生组] 耗时最短的路径

    ID: 17464 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>图论2025最短路蓝桥杯国赛

[蓝桥杯 2025 国 Python/Java 研究生组] 耗时最短的路径

Problem Description

An explorer needs to pass through a maze full of spacetime rifts. There are nn spacetime rifts (called nodes), numbered 1n1 \sim n. The explorer may stay at any node for any length of time.

There are mm paths between the rifts. Each path is described by (ui,vi,wi,si,ei)(u_i, v_i, w_i, s_i, e_i), meaning there is an undirected path between node uiu_i and node viv_i. Traversing this path takes time wiw_i, and the explorer can enter and traverse it only when the current time is within the interval [si,ei][s_i, e_i] (therefore, after traversing this path, the arrival time at viv_i must be within [si+wi,ei+wi][s_i + w_i, e_i + w_i]).

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 [si,ei][s_i, e_i]. This skill can be used at most kk times.

Initially, the explorer is at node 11 at time 00. What is the minimum time needed to reach node nn from node 11?

Input Format

The first line contains three integers n,m,kn, m, k, separated by one space.

The next mm lines each contain five integers ui,vi,wi,si,eiu_i, v_i, w_i, s_i, e_i, separated by one space, describing the ii-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 1-1.

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 131 \to 3, which takes 6 units of time. Taking 1231 \to 2 \to 3 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 121 \to 2, then use the skill once on 232 \to 3, for a total time of 4.

Constraints and Conventions

For 10%10\% of the testdata, 2n52 \le n \le 5.

For 20%20\% of the testdata, 2n102 \le n \le 10.

For 40%40\% of the testdata, 2n1002 \le n \le 100.

For 60%60\% of the testdata, 2n10002 \le n \le 1000.

For 80%80\% of the testdata, 2n100002 \le n \le 10000.

For all testdata, 2n500002 \le n \le 50000, $1 \le m \le \min\left(\dfrac{n(n-1)}{2}, 10^5\right)$, 0k100 \le k \le 10, 1ui,vin1 \le u_i, v_i \le n, 0si,ei4×1030 \le s_i, e_i \le 4 \times 10^3.

Translated by ChatGPT 5