#P3568. [POI 2014] WAZ-Snake
[POI 2014] WAZ-Snake
Description
A snake fills a board completely. The snake is divided into segments numbered from to . Consecutive segments (i.e., and ) must occupy squares that share an edge. Some segment numbers on the board are erased. Can you reconstruct the snake?
Constraints: .
Description
Input Format
The first line contains an integer (), the length of the board.
The next three lines describe the board. The -th of these lines contains integers () for .
If , then is the number of the snake’s segment occupying the -th square of the -th row. If , then the number on this square is unknown.
It is guaranteed that there is at least one valid reconstruction.
Output Format
Print three lines. The -th line should contain positive integers ().
All numbers together must form a permutation of . For every with , it must hold that . Moreover, for every from to , the squares containing and must share an edge.
If multiple solutions exist, output any of them.
9
0 0 5 0 17 0 0 0 21
8 0 0 3 16 0 0 25 0
0 0 0 0 0 0 0 0 23
7 6 5 4 17 18 19 20 21
8 1 2 3 16 15 26 25 22
9 10 11 12 13 14 27 24 23
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号