#P13955. [ICPC 2023 Nanjing R] 延伸距离
[ICPC 2023 Nanjing R] 延伸距离
Description
Given points arranged into rows and columns, there are weighted bidirectional edges between adjacent points. That is, let be the point on the -th row and the -th column, for all and , there is an edge between and if and only if .
BaoBao will begin his journey at any point on the first column and finish the journey at any point on the last column. He can travel along the edges in both directions. The distance of a path is defined as the sum of the weight of the edges in the path. Among all the paths from the first column to the last column, BaoBao will choose the shortest path.
Little Cyan Fish hopes BaoBao to better enjoy the journey, so he tries to increase the weight of some edges before BaoBao begins traveling. Specifically, Little Cyan Fish can increase the weight of any edge by in one operation. He hopes the distance of BaoBao's path can increase by after all operations. Please help him calculate the minimum number of operations needed and output the corresponding solution.
Input Format
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first line contains three integers , and (, , ) indicating the number of rows and columns, and the increment on the length of the shortest path.
For the following lines, the -th line contains integers () where indicates the weight of the edge between and .
For the following lines, the -th line contains integers () where indicates the weight of the edge between and .
It is guaranteed that the sum of of all test cases will not exceed .
Output Format
For each test case:
First output one line containing one integer indicating the minimum number of operations needed.
Then output lines. The -th line contains integers () separated by a space, where indicates the weight of the edge between and after all operations.
Then output lines. The -th line contains integers () separated by a space, where indicates the weight of the edge between and after all operations.
If there are multiple valid answers, output any of them.
Please, DO NOT output extra spaces at the end of each line, or your solution may be considered incorrect!
2
3 4 6
2 1 15
7 1 9
13 3 2
3 6 1 2
5 2 15 3
3 3 3
1 1
2 2
3 3
1 1 1
2 2 2
9
2 3 15
7 1 10
13 3 4
3 6 3 2
5 4 15 3
4
4 1
3 2
3 3
1 1 1
2 2 2
Hint
The first sample test case is illustrated below. The graph on the left is the original graph and the graph on the right is the graph after increasing the weight of some edges. Shortest paths of each graph are marked by red lines.
:::align{center}
:::
京公网安备 11011102002149号