P3568 [POI 2014] WAZ-Snake
题目描述
A snake fills a  board completely.
Successive segments of the snake are numbered from  to .
The segments with successive numbers (i.e., 1 and 2, 2 and 3, 3 and 4...) occupy squares that share an edge.
For example, a snake can fill a  board as follows:
The snake's segment numbers in some of the squares have been erased.
Can you reconstruct the snake?
一只蛇被放在了一块3\*n的木板上(填充满了),蛇被分为多个小段,小段的编号是1到3n。比如说蛇可以填写一个3\*9的木板,如下所示:
部分木板上的蛇段已删遮挡。
你能重建蛇吗?
输入格式
In the first line of the standard input, there is a single integer  (), the length of the board.
The three lines that follow describe the board; the -th of them contains  integers  ( for ).
If , then  is the number of the snake's segment occupying the -th square of the -th row of the board.
If on the other hand , then the number of the snake's segment on this square is unknown.
In tests worth 15% of the total score  holds, in those worth 40% of the total score  holds, and finally, in those worth 70% of the total score  holds.
在标准输入的第一行中,有一个整数n(1
输出格式
Your program is to print three lines to the standard output.
The -th lines should hold  positive integers  (for ).
All the numbers  together should be a permutation of the numbers from  to .
The output numbers should be a valid reconstruction of the snake, i.e., they should be consistent with the (positive) input numbers and satisfy aforementioned constraints.
You may assume that there is at least one valid reconstruction of the snake.
If there is more than one, your program can print any valid reconstruction.
将所有aij为0的蛇段补齐