2035: [USACO 2025 January Contest, Silver] Problem 3. Table Recovery

文件提交:无需freopen 内存限制:128 MB 时间限制:1.000 S
评测方式:普通裁判 命题人:
提交:1 解决:1

题目描述

Bessie has an  () addition table where the integer in the cell at row  and column  is , for all . For example, for , the table would look like this:

2 3 4
3 4 5
4 5 6

Unfortunately, Elsie got ahold of the table and permuted it by performing the following three types of operations as many times as she wanted.

  1. Swap two rows
  2. Swap two columns
  3. Select two values  and  that are both present in the table, then simultaneously change every occurrence of  to  and every occurrence of  to .

Elsie will always perform operations in increasing order of type; that is, she performs as many operations as she likes (possibly none) first of type , then of type , and finally of type .

Help Bessie recover a possible state of the table after Elsie finished applying all of her operations of types  and , but before applying any operations of type . There may be multiple possible answers, in which case you should output the lexicographically smallest one.

To compare two tables lexicographically, compare the first entries at which they differ, when reading both tables in the natural order (rows from top to bottom, left to right within a row).

输入

The first line contains .

The next  lines each contain  integers, representing Bessie's addition table after Elsie has permuted it.

输出

The lexicographically minimum possible state of the table after all operations of types 1 and 2, but before any operations of type 3. It is guaranteed that the answer exists.

样例输入

1
2

样例输出

2

提示

Regardless of what operations Elsie performs, the table won't change.

SAMPLE INPUT:

3 4 2 

5 2 3 

6 3 5


	

SAMPLE OUTPUT:

4 2 3

5 3 4 

6 4 5

Here is a possible sequence of operations Elsie might have performed.

2 3 4

3 4 5 

4 5 6 

-> (op 1: swap columns 2 and 3) 

2 4 3 

3 5 4 

4 6 5 

-> (op 1: swap columns 1 and 2) 

4 2 3 

5 3 4 

6 4 5 

-> (op 3: swap values 2 and 3) 

4 3 2 

5 2 4 

6 4 5 

-> (op 3: swap values 3 and 4) 

3 4 2 

5 2 3 

6 3 5 

Note: the following is also a possible state of the table after operations of types 1 and 2, but it is not the lexicographically smallest because the second entry of the first row is larger than in the correct answer. 

4 6 5 

3 5 4 

2 4 3


SAMPLE INPUT: 

8 10 5 6 7 4 

12 11 10 4 8 2 

5 4 6 7 9 8 

10 2 4 8 5 12 

6 8 7 9 3 5 

4 12 8 5 6 10 


SAMPLE OUTPUT: 

7 5 8 9 10 6 

4 2 5 6 7 3 

8 6 9 10 11 7 

5 3 6 7 8 4 

9 7 10 11 12 8 

6 4 7 8 9 5


SCORING:

  • Inputs 4-5: 
  • Inputs 6-7: 
  • Inputs 8-11: 
  • Inputs 12-15: No additional constraints.


来源/分类