#P5468. [NOI2019] 回家路线

    ID: 6204 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2019NOIO2优化深度优先搜索 DFS生成树

[NOI2019] 回家路线

Background

The original version of this problem has relatively weak testdata. If you want to test with stronger testdata, you can go to P6302. Except for the Constraints, everything is the same as the original problem.

Problem Description

In the railway system of Cat Kingdom, there are nn stations numbered from 11 to nn. A kitten plans to start from station 11 and take trains to return to its home at station nn. It has checked the available trains: there are mm trains in total, numbered from 11 to mm. The kitten will arrive at station 11 at time 00.

For train ii, it departs from station xix_i at time pip_i and goes directly to station yiy_i, arriving at time qiq_i. The kitten can only board train ii at time pip_i, and can only get off train ii at time qiq_i. The kitten can reach station nn by transferring multiple times.

A transfer means the following: for two trains, say train uu and train vv, if yu=xvy_u = x_v and qupvq_u \leq p_v, then after taking train uu, the kitten can wait at station yuy_u for pvqup_v - q_u time units, and then take train vv at time pvp_v.

The kitten wants to get home while reducing the trouble on the way, and it measures this by an “irritation value”.

  • While the kitten is waiting at a station, the irritation value increases. For a wait of t(t0)t (t \geq 0) time units, the irritation value increases by At2+Bt+CAt^2 + Bt + C, where A,B,CA, B, C are given constants. Note: the time it stays at station 11 starting from time 00 before boarding the first train also counts as one wait.

  • If the kitten finally arrives at station nn at time zz, the irritation value increases by an additional zz.

Formally, suppose the kitten takes kk trains in total, and the sequence of train indices is s1,s2,,sks_1, s_2, \cdots , s_k. This plan is called a feasible route home if and only if it satisfies:

  1. xs1=1x_{s1} = 1 , ysk=ny_{sk} = n

  2. For all j(1j<k)j (1 \leq j < k), ysj=xsj+1y_{sj} = x_{s_{j+1}} and qsjpsj+1q_{sj}\leq p_{s_{j+1}}

For this route home, the irritation value is:

$$q_{s_k}+(A\times p_{s_1}^2+B\times p_{s_1}+C)+\sum_{j=1}^{k-1}(A(p_{s_{j+1}}-q_{s_j})^2+B(p_{s_{j+1}}-q_{s_j})+C)$$

The kitten wants the irritation value to be as small as possible. Please compute, among all feasible routes home, the minimum possible irritation value. The problem guarantees that at least one feasible route exists.

Input Format

The first line contains five integers n,m,A,B,Cn, m, A, B, C. Their meanings are as described in the statement.

The next mm lines: line ii contains four integers xi,yi,pi,qix_i, y_i, p_i, q_i, representing the departure station, arrival station, departure time, and arrival time of train ii.

Output Format

Output one integer in a single line, the required answer.

3 4 1 5 10
1 2 3 4
1 2 5 7
1 2 6 8
2 3 9 10
94
4 3 1 2 3
1 2 2 3
2 3 5 7
3 4 7 9
34

Hint

More Samples

You can obtain more samples through the additional files.

Sample 3

See route/route3.in and route/route3.ans in the additional files.

The data type of this sample is the same as that of final test points 585 \sim 8.

Sample 4

See route/route4.in and route/route4.ans in the additional files.

The data type of this sample is the same as that of final test points 111411 \sim 14.

Sample 5

See route/route5.in and route/route5.ans in the additional files.

The data type of this sample is the same as that of final test points 182018 \sim 20.

Explanation for Sample 1

There are three feasible routes home:

  • Take trains 1 and 4 in order. The irritation value is: $10 + (1 \times 3^2 + 5 \times 3 + 10) + (1 \times (9 - 4)^2 + 5 \times (9 - 4) + 10)= 104$
  • Take trains 2 and 4 in order. The irritation value is: $10 + (1 \times 5^2 + 5 \times 5 + 10) + (1 \times (9 - 7)^2 + 5 \times (9 - 7) + 10)= 94$
  • Take trains 3 and 4 in order. The irritation value is: $10 + (1 \times 6^2 + 5 \times 6 + 10) + (1 \times (9 - 8)^2 + 5 \times (9 - 8) + 10)= 102$

The second route has the smallest irritation value, which is 9494.

Constraints

For all test points: $2\le n\le 10^5,1\le m\le 2\times 10^5,0 \le A \le 10 , 0 \le B, C \le 10^6,1 \le x_i, y_i \le n , x_i \neq y_i , 0 \le p_i < q_i \le 10^3$.

The specific limits for each test point are shown in the table below:

::cute-table{tuack}

Test Point ID nn mm Special Limits on A,B,CA,B,C Other Special Conditions
121\sim 2 100\le 100 =n1=n-1 None yi=xi+1y_i=x_i+1
343\sim 4 ^ 100\le 100 A=B=C=0A=B=C=0 ^
585\sim 8 2×103\le 2\times 10^3 4×103\le 4\times 10^3 ^ xi<yix_i<y_i
99 ^ A=B=0A=B=0 ^
1010 A=0A=0
111411\sim 14 None
1515 105\le 10^5 2×105\le 2\times 10^5 A=B=0A=B=0 ^
161716\sim 17 ^ A=0A=0
182018\sim 20 None

Translated by ChatGPT 5