#P6302. [NOI2019] 回家路线 加强版
[NOI2019] 回家路线 加强版
Background
This problem is an enhanced version of NOI 2019 Route Home. Except for the Constraints, it is the same as the original problem.
Problem Description
In the railway system of Cat Kingdom, there are stations, numbered from . The kitten plans to start from station and take trains to return to station , where its home is. It checked the trains it can take. There are trains in total, numbered from . The kitten will arrive at station at time . For train , it departs from station at time and arrives directly at station 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: for two trains, suppose they are train and train . If and , then after taking train , the kitten can wait at station for time units, and board train at time .
The kitten only wants to get home and reduce the trouble on the way, so it uses an irritation value to measure this.
-
When the kitten waits at a station, its irritation value increases. For one wait of time units, the irritation value increases by , where are given constants. Note: the time spent staying at station starting from time before boarding the first train is also counted as one wait.
-
If the kitten finally arrives at station at time , the irritation value will further increase by .
Formally, suppose the kitten takes trains in total, and the train numbers it takes in order can be written as a sequence . This plan is called a feasible route home if and only if it satisfies the following two conditions:
-
-
For all , and
For this route home, the irritation value the kitten gets 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 help it find the minimum irritation value among all feasible routes home. The problem guarantees that there is at least one feasible route home.
Input Format
The first line contains five integers . The meanings of the variables are given in the description.
The next lines describe the trains. In line , there are four integers , representing the departure station, arrival station, departure time, and arrival time of train , respectively.
Output Format
Output only one line with one integer, 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
For all testdata, it is guaranteed that , , , , , , and .
Translated by ChatGPT 5