Codeforces Round 814 (Div. 1)
E
Impressionism
Codeforces
3500
原题
← DF →
翻译中…

Burenka has two pictures $a$ and $b$, which are tables of the same size $n \times m$. Each cell of each painting has a color — a number from $0$ to $2 \cdot 10^5$, and there are no repeating colors in any row or column of each of the two paintings, except color $0$.

翻译中…

Burenka wants to get a picture $b$ from the picture $a$. To achieve her goal, Burenka can perform one of $2$ operations: swap any two rows of $a$ or any two of its columns. Tell Burenka if she can fulfill what she wants, and if so, tell her the sequence of actions.

翻译中…

The rows are numbered from $1$ to $n$ from top to bottom, the columns are numbered from $1$ to $m$ from left to right.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $m$ ($1 \leq n \cdot m \leq 2 \cdot 10^5$) — the sizes of the table.

翻译中…

The $i$-th of the next $n$ lines contains $m$ integers $a_{i, 1}, a_{i, 2}, \ldots, a_{i, m}$ ($0 \leq a_{i,j} \leq 2 \cdot 10^5$) — the colors of the $i$-th row of picture $a$. It is guaranteed that there are no identical colors in the same row or column, except color $0$.

翻译中…

The $i$-th of the following $n$ lines contains $m$ integers $b_{i, 1}, b_{i, 2}, \ldots, b_{i, m}$ ($0 \leq b_{i,j} \leq 2 \cdot 10^5$) — the colors of the $i$-th row of picture $b$. It is guaranteed that there are no identical colors in the same row or column, except color $0$.

翻译中…

Output

翻译中…

In the first line print the number $-1$ if it is impossible to achieve what Burenka wants, otherwise print the number of actions in your solution $k$ ($0 \le k \le 2 \cdot 10^5$). It can be proved that if a solution exists, then there exists a solution where $k \le 2 \cdot 10^5$.

翻译中…

In the next $k$ lines print the operations. First print the type of the operation ($1$ — swap rows, $2$ — columns), and then print the two indices of rows or columns to which the operation is applied.

翻译中…

Note that you don't have to minimize the number of operations.

翻译中…

样例

Input #1
3 3
1 0 2
0 0 0
2 0 1
2 0 1
0 0 0
1 0 2
Output #1
1
1 1 3
InputCopy OutputCopy
Input #2
4 4
0 0 1 2
3 0 0 0
0 1 0 0
1 0 0 0
2 0 0 1
0 3 0 0
0 1 0 0
0 0 1 0
Output #2
4
1 3 4
2 3 4
2 2 3
2 1 2
InputCopy OutputCopy
Input #3
3 3
1 2 0
0 0 0
0 0 0
1 0 0
2 0 0
0 0 0
Output #3
-1
InputCopy OutputCopy
题目信息
题号
1718E
时间限制
2 s
内存限制
256 MB
标签
构造
图论
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。