#P1142. [POI2009]Tab

[POI2009]Tab

[POI2009] TAB-Arrays

题目描述

Let us consider an array of size filled with pairwise different integers.

The following operations are allowed on the array:

interchanging two rows, interchanging two columns.

We call two arrays alike if one of them can be obtained from the other by a sequence of aforementioned operations.

Write a programme that for a given set of pairs of arrays tells which pairs are alike.

给出两个n*m的矩阵,保证每个矩阵内元素互不相同且权值均在[-10^6,10^6]之间,请能否把其中一个矩阵通过若干次交换两行或者交换两列的操作变成另外一个矩阵

输入格式

The first line of the standard input contains one integer () denoting the number of pairs of arrays.

Then descriptions of successive array pairs follow in subsequent lines.

Each description starts with a line holding two integers and (), separated by a single space, that denote the common number of rows and columns of the arrays, respectively.

The lines that follow describe the first array.

In the -th of them there are integers (), separated by single spaces…

输出格式

Your programme should print out lines to the standard output.

The -th of these should hold one word: "TAK" (yes in Polish) if the arrays of the -th pair are alike, or "NIE" (no in Polish) otherwise.

样例 #1

样例输入 #1

2
4 3
1 2 3
4 5 6
7 8 9
10 11 12
11 10 12
8 7 9
5 4 6
2 1 3
2 2
1 2
3 4
5 6
7 8

样例输出 #1

TAK
NIE

原始数值约束补充

测试用例数 1≤t≤101\le t\le10;每个用例的矩阵大小满足 1≤n,m≤10001\le n,m\le1000。每个矩阵内的数两两不同,元素在 [−106,106][-10^6,10^6] 内。本题原文没有额外的跨用例矩阵元素总数上限,实现应按最多10个1000乘1000矩阵对处理。