#P1275. 魔板
魔板
Description
There is a kind of magic board: it is a rectangular panel divided into rows and columns, forming cells. Each cell contains a small light bulb, and each bulb has two possible states (on or off). We can transform the board from one state to another using several operations. There are two types of operations:
- Choose any row and toggle the state of all bulbs in that row, i.e., on becomes off and off becomes on.
- Choose any two columns and swap their positions.
Of course, not every pair of states can be transformed into each other through these operations.
Your task is to determine whether two given board states can be transformed into each other.
Input Format
The file contains multiple datasets. The first line contains an integer (), indicating there are datasets.
For each dataset, the first line contains two integers and ().
The next lines describe the first magic board. Each line contains numbers ( or ), separated by spaces. If the -th number in the -th row is , then the bulb at row , column is "on"; otherwise it is "off".
The following lines describe the second magic board in the same format.
There are no blank lines between any two datasets.
Output Format
Output lines, each describing the result for one dataset in order.
If the two boards can be transformed into each other, output ; otherwise, output . (Note: please use uppercase letters.)
2
3 4
0 1 0 1
1 0 0 1
0 0 0 0
0 1 0 1
1 1 0 0
0 0 0 0
2 2
0 0
0 1
1 1
1 1
YES
NO
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号