#P10652. [ROI 2017] 前往大都会 (Day 1)
[ROI 2017] 前往大都会 (Day 1)
Problem Description
ROI has cities and rail lines. Each rail line runs in one direction. The -th rail line passes through and stops at cities in order, where the track length from is .
If multiple rail lines pass through city , then you can transfer to another rail line at city . (For each rail line, you may get on or off at any stop.)
You need to find a path from city to city such that the total length is minimized, and subject to that, the sum of squares of the distances traveled on trains between every pair of adjacent transfer points along the path is maximized.
Note: both the start point and the end point are transfer points. The problem guarantees that a solution exists.
Input Format
The first line contains two integers , meaning there are cities and rail lines.
The next lines describe the rail lines. Each line starts with an integer denoting the length of the rail line, followed by integers in the form $v_{i,1}, t_{i,1}, v_{i,2}, \dots, v_{i,l_i}, t_{i,l_i}, v_{i,l_i+1}$, with meanings as described above. It is guaranteed that there are no repeated cities within a single rail line.
Output Format
Output one line with two integers. The first number is the shortest path length, and the second number is the maximum possible sum of squares.
2 1
1 1 3 2
3 9
5 2
4 1 3 2 3 3 5 5 10 4
3 4 2 2 1 3 4 1
9 35
5 2
3 1 1 2 2 3 3 4
3 2 2 3 3 4 4 5
10 82
Hint
Sample Explanation
For sample set #2:
Taking line directly from city to city is not the best plan (it cannot achieve the shortest time). The best plan is:
Take line from city to city .
Transfer to line and ride to city .
Transfer back to line and ride to city .
In this case, the sum of squares is .
For sample set #3:
No matter at which station you transfer to line on the way, the result is the same. The sum of squares is .
Constraints
Note: This problem provides only part of the testdata. For the full testdata, please go to LOJ P2769 for judging.
For all data: , , . Let .
| Subtask ID | Score | Special Property | ||
|---|---|---|---|---|
| None | ||||
Translated by ChatGPT 5