#P5468. [NOI2019] 回家路线
[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 stations numbered from to . A kitten plans to start from station and take trains to return to its home at station . It has checked the available trains: there are trains in total, numbered from to . The kitten will arrive at station at time .
For train , it departs from station at time and goes directly to station , arriving at time . The kitten can only board train at time , and can only get off train at time . The kitten can reach station by transferring multiple times.
A transfer means the following: for two trains, say train and train , if and , then after taking train , the kitten can wait at station for time units, and then take train at time .
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 time units, the irritation value increases by , where are given constants. Note: the time it stays at station starting from time before boarding the first train also counts as one wait.
-
If the kitten finally arrives at station at time , the irritation value increases by an additional .
Formally, suppose the kitten takes trains in total, and the sequence of train indices is . This plan is called a feasible route home if and only if it satisfies:
-
,
-
For all , and
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 . Their meanings are as described in the statement.
The next lines: line contains four integers , representing the departure station, arrival station, departure time, and arrival time of train .
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 .
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 .
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 .
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 .
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 | Special Limits on | Other Special Conditions | ||
|---|---|---|---|---|
| None | ||||
| ^ | ^ | |||
| ^ | ||||
| ^ | ^ | |||
| None | ||||
| ^ | ||||
| ^ | ||||
| None | ||||
Translated by ChatGPT 5