knightnemo commited on
Commit
2c590bc
·
verified ·
1 Parent(s): dc9d16b

Upload code_segments/segment_65.txt with huggingface_hub

Browse files
Files changed (1) hide show
  1. code_segments/segment_65.txt +29 -0
code_segments/segment_65.txt ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ You have been given a matrix $a$ of size $n$ by $m$, containing a permutation of integers from $1$ to $n \cdot m$.
2
+
3
+ A permutation of $n$ integers is an array containing all numbers from $1$ to $n$ exactly once. For example, the arrays $[1]$, $[2, 1, 3]$, $[5, 4, 3, 2, 1]$ are permutations, while the arrays $[1, 1]$, $[100]$, $[1, 2, 4, 5]$ are not.
4
+
5
+ A matrix contains a permutation if, when all its elements are written out, the resulting array is a permutation. Matrices $[[1, 2], [3, 4]]$, $[[1]]$, $[[1, 5, 3], [2, 6, 4]]$ contain permutations, while matrices $[[2]]$, $[[1, 1], [2, 2]]$, $[[1, 2], [100, 200]]$ do not.
6
+
7
+ You can perform one of the following two actions in one operation:
8
+
9
+ * choose columns $c$ and $d$ ($1 \le c, d \le m$, $c \ne d$) and swap these columns; * choose rows $c$ and $d$ ($1 \le c, d \le n$, $c \ne d$) and swap these rows.
10
+
11
+ You can perform any number of operations.
12
+
13
+ You are given the original matrix $a$ and the matrix $b$. Your task is to determine whether it is possible to transform matrix $a$ into matrix $b$ using the given operations.
14
+
15
+ The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The descriptions of the test cases follow.
16
+
17
+ The first line of each test case description contains $2$ integers $n$ and $m$ ($1 \le n, m \le n \cdot m \le 2 \cdot 10^5$) — the sizes of the matrix.
18
+
19
+ The next $n$ lines contain $m$ integers $a_{ij}$ each ($1 \le a_{ij} \le n \cdot m$). It is guaranteed that matrix $a$ is a permutation.
20
+
21
+ The next $n$ lines contain $m$ integers $b_{ij}$ each ($1 \le b_{ij} \le n \cdot m$). It is guaranteed that matrix $b$ is a permutation.
22
+
23
+ It is guaranteed that the sum of the values $n \cdot m$ for all test cases does not exceed $2 \cdot 10^5$.
24
+
25
+ For each test case, output "YES" if the second matrix can be obtained from the first, and "NO" otherwise.
26
+
27
+ You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.
28
+
29
+ In the second example,