#P10652. [ROI 2017] 前往大都会 (Day 1)

    ID: 12151 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2017O2优化斜率优化最短路ROI(俄罗斯)

[ROI 2017] 前往大都会 (Day 1)

Problem Description

ROI has nn cities and mm rail lines. Each rail line runs in one direction. The ii-th rail line passes through and stops at cities vi,1,vi,2,,vi,li+1v_{i,1}, v_{i,2}, \dots, v_{i,l_i+1} in order, where the track length from vi,jvi,j+1v_{i,j} \to v_{i,j+1} is ti,jt_{i,j}.

If multiple rail lines pass through city uu, then you can transfer to another rail line at city uu. (For each rail line, you may get on or off at any stop.)

You need to find a path from city 11 to city nn 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 n,mn, m, meaning there are nn cities and mm rail lines.

The next mm lines describe the rail lines. Each line starts with an integer lil_i denoting the length of the rail line, followed by 2li+12l_i+1 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 11 directly from city 11 to city 55 is not the best plan (it cannot achieve the shortest time). The best plan is:

Take line 11 from city 11 to city 22.

Transfer to line 22 and ride to city 33.

Transfer back to line 11 and ride to city 55.

In this case, the sum of squares is 32+12+52=353^2 + 1^2 + 5^2 = 35.

For sample set #3:

No matter at which station you transfer to line 22 on the way, the result is the same. The sum of squares is 12+92=821^2 + 9^2 = 82.

Constraints

Note: This problem provides only part of the testdata. For the full testdata, please go to LOJ P2769 for judging.

For all data: 1m1061 \le m \le 10^6, 1vi,jn1 \le v_{i,j} \le n, 1ti,j10001 \le t_{i,j} \le 1000. Let sum=lisum=\sum l_i.

Subtask ID Score 1n1 \le n \le 1sum1 \le sum \le Special Property
11 1010 1010 2020 li=1l_i=1
22 10310^3 10310^3
33 1717 None
44 10510^5
55 1919 10410^4 2×1052 \times 10^5
66 2×1052 \times 10^5
77 88 10610^6

Translated by ChatGPT 5