#P14051. [SDCPC 2019] Triangle City

[SDCPC 2019] Triangle City

题目描述

Triangle City is a city with n(n+1)2\frac{n(n+1)}{2} intersections arranged into nn rows and nn columns, where the ii-th row contains ii intersections.

The intersections are connected by bidirectional roads. Formally, if we denote (i,j)(i, j) as the intersection on the ii-th row and the jj-th column, for all 1ji<n1 \le j \le i < n,

  • there is a road whose length is ai,ja_{i, j} connecting intersection (i,j)(i, j) and (i+1,j)(i + 1, j), and
  • there is a road whose length is bi,jb_{i, j} connecting intersection (i,j)(i, j) and (i+1,j+1)(i + 1, j + 1), and
  • there is a road whose length is ci,jc_{i, j} connecting intersection (i+1,j)(i + 1, j) and (i+1,j+1)(i + 1, j + 1).

What's more, for all 1ji<n1 \le j \le i < n, there exists a triangle whose sides are of length ai,ja_{i, j}, bi,jb_{i, j} and ci,jc_{i, j}. That's why the city is called the Triangle City!

Our famous traveler BaoBao has just arrived in the Triangle City, planning to start his journey from intersection (1,1)(1, 1) and end his trip at intersection (n,n)(n, n). To fully enjoy the landscape, BaoBao would like to find the longest path from (1,1)(1, 1) to (n,n)(n, n) such that each road is passed no more than once. Please help BaoBao find such a path.

Recall that if the sides of a triangle are of length aa, bb and cc, we can infer that a+b>ca + b > c, a+c>ba + c > b and b+c>ab + c > a.

输入格式

There are multiple test cases. The first line of the input contains an integer TT, indicating the number of test cases. For each test case:

The first line contains an integer nn (2n3002 \le n \le 300), indicating the size of the city.

For the following (n1)(n - 1) lines, the ii-th line contains ii integers ai,1,ai,2,,ai,ia_{i, 1}, a_{i, 2}, \dots, a_{i, i} (1ai,j1091 \le a_{i, j} \le 10^9), where ai,ja_{i, j} indicates the length of the road connecting intersection (i,j)(i, j) and (i+1,j)(i + 1, j).

For the following (n1)(n - 1) lines, the ii-th line contains ii integers bi,1,bi,2,,bi,ib_{i, 1}, b_{i, 2}, \dots, b_{i, i} (1bi,j1091 \le b_{i, j} \le 10^9), where bi,jb_{i, j} indicates the length of the road connecting intersection (i,j)(i, j) and (i+1,j+1)(i + 1, j + 1).

For the following (n1)(n - 1) lines, the ii-th line contains ii integers ci,1,ci,2,,ci,ic_{i, 1}, c_{i, 2}, \dots, c_{i, i} (1ci,j1091 \le c_{i, j} \le 10^9), where ci,jc_{i, j} indicates the length of the road connecting intersection (i+1,j)(i + 1, j) and (i+1,j+1)(i + 1, j + 1).

It's guaranteed that the sum of nn of all test cases will not exceed 5×103 5 \times 10^3.

输出格式

For each test case output three lines.

The first line contains one integer ll, indicating the length of the longest path from (1,1)(1, 1) to (n,n)(n, n) such that each road is passed no more than once.

The second line contains one integer mm, indicating the number of intersections on the longest path.

The third line contains 2m2m integers i1,j1,i2,j2,,im,jmi_1, j_1, i_2, j_2, \dots, i_m, j_m separated by a space, where (ik,jk)(i_k, j_k) indicates the kk-th intersection on the longest path. Note that according to the description, there must be (i1,j1)=(1,1)(i_1, j_1) = (1, 1) and (im,jm)=(n,n)(i_m, j_m) = (n, n).

If there are multiple valid answers, you can output any of them.

Please, DO NOT output extra spaces at the end of each line, or your solution may be considered incorrect!

3
2
3
2
4
2
1
1
1
3
100
100 100
1
100 1
100
100 100
7
3
1 1 2 1 2 2
2
3
1 1 2 1 2 2
700
8
1 1 2 1 3 2 2 2 2 1 3 1 3 2 3 3

提示

The sample test cases are shown below:

:::align{center} :::