#P10199. [湖北省选模拟 2024] 时与风 / wind

[湖北省选模拟 2024] 时与风 / wind

Background

The wind brings the seeds of stories, and time turns them into myths.

Problem Description

You are flying among NN anchor points along MM directed air routes using the Wings of Wind. The anchor points are numbered 1,2,,N1,2,\cdots,N, and the directed routes are numbered 1,2,,M1,2,\cdots,M. For route ii, the starting anchor point is uiu_i, and the destination anchor point is viv_i.

Due to Barbatos's mysterious connection with time, route ii opens at time OiO_i and closes after time CiC_i. That is, for any OitCiO_i \le t \le C_i, you can enter route ii from anchor point uiu_i at time tt. After entering a route, spatially you will arrive directly at anchor point viv_i. Temporally, the time will change with equal probability to a real-valued moment corresponding to some real number in [Li,Ri][L_i,R_i]. Note that after arriving at an anchor point, you must immediately enter the next route at the same moment; otherwise, you must end the flight there.

You will start from anchor point SS and try to visit anchor point i (1iN)i\ (1\le i\le N). You need to determine a path E1,E2,E3,,EkE_1,E_2,E_3,\cdots,E_k, where Ex (1xk)E_x\ (1\le x\le k) denotes a route. The path must satisfy that E1E_1 starts from anchor point SS, EkE_k arrives at anchor point ii, and for 1j<k1\le j<k, the destination anchor point of EjE_j is the same as the starting anchor point of Ej+1E_{j+1}. A path is a stable path if and only if, no matter how the time changes after each route traversal, you can complete the entire path. The arrival time of a stable path is, when traveling to anchor point ii along this path, the latest possible moment at which you may arrive at anchor point ii. The stable arrival time TiT_i of anchor point i (iS)i\ (i \neq S) is the minimum among the arrival times of all stable paths that reach ii. You may start at any non-negative time. If there is no stable path to visit anchor point ii, or if i=Si=S, then Ti=0T_i=0.

Please compute the maximum value of Ti (1iN)T_i\ (1\le i\le N).

Input Format

The input consists of M+1M+1 lines.

The first line contains three integers N,M,SN,M,S, representing the number of anchor points, the number of routes, and the starting anchor point.

The next MM lines each contain six integers ui,vi,Oi,Ci,Li,Riu_i,v_i,O_i,C_i,L_i,R_i, describing route ii. The meanings of the variables are given in the description.

Output Format

Output one line with one integer, representing the maximum value among TiT_i.

4 10 1
4 2 6 20111 6 11900
2 4 2 10786 13 23576
2 1 3 5274 16 13903
2 1 2 17162 1 26120
1 2 1 42040 11 16065
2 1 4 23690 18 26541
2 3 9 18977 2 26795
4 1 4 51880 1 25060
1 4 13 17776 3 28236
1 4 1 19112 1 10131
26795
见选手目录下的 wind/wind2.in 与 wind/wind2.ans。

见选手目录下的 wind/wind3.in 与 wind/wind3.ans。

见选手目录下的 wind/wind4.in 与 wind/wind4.ans。

Hint

Sample Explanation 1

For anchor point 11, clearly T1=0T_1=0.

For anchor point 22, along the path 121 \rightarrow 2, T2=16065T_2=16065.

For anchor point 33, along the path 1231 \rightarrow 2 \rightarrow 3, T3=26795T_3=26795.

For anchor point 44, along the path 141 \rightarrow 4, T4=10131T_4 = 10131.

Therefore, the answer is maxTi=T3=26795\max T_i=T_3=26795.

Subtasks

For all testdata, it is guaranteed that 1N,M5×1051 \le N,M \le 5\times 10^5, 1Oi,Li201 \le O_i,L_i \le 20, 1OiCi1091 \le O_i \le C_i \le 10^9, 1LiRi1091 \le L_i \le R_i \le 10^9, and 1SN1\le S \le N.

Test Point ID NN\le MM\le Ci,RiC_i,R_i\le Special Property
141\sim 4 2020 10910^9 None
585\sim 8 10510^5 10310^3
9109\sim 10 5×1055\times 10^5 A
111211\sim 12 10510^5 2020 None
131413\sim 14 5×1055\times 10^5 10310^3
152015\sim 20 10910^9

Special Property A: The number of routes connected to a single anchor point does not exceed 100100.

Translated by ChatGPT 5