#graph503. 矩阵问题
矩阵问题
Matrix Problem
Problem Description
There is an matrix; you need to fill in a number at each position .
There are several constraints. For each position , it must satisfy .
Further, for all , it must satisfy . For all , it must satisfy .
Input Format
The first line contains two integers .
The next lines each contain numbers .
The next lines each contain numbers .
The next lines each contain numbers .
The next lines each contain numbers .
The input guarantees that a solution always exists.
Output Format
Output lines of numbers each, representing one valid solution. Any valid solution is accepted.
Sample Input
2 2
0 1
2 3
2 3
4 5
4
8
4 5
Sample Output
1 2
3 4
Constraints
; all bounds are within the ranges given in the input; a solution always exists.
Hint
- Every constraint is of the form "" or "", which is a classic system of difference constraints. Build a graph and run the Bellman-Ford / SPFA shortest-path algorithm to find one feasible assignment.