CF1475F Unusual Matrix

题目描述

给你两个 $n\times n$ 的 $\tt 01$ 矩阵,你可以进行如下两种操作: - 垂直异或:选中一列,将这一列的每个元素分别异或上 $1$。 - 水平有哦:选中一行,将这一行的每个元素分别异或上 $1$。 给定 $a,b$ 两个矩阵,问你 $a$ 是否可以在进行有限次操作后变为 $b$。 例如: $$ a=\begin{pmatrix} 1 & 1 & 0 \\ 0 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix},b=\begin{pmatrix} 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end{pmatrix} $$ 先使第一行进行水平异或: $$ a=\begin{pmatrix} 0 & 0 & 1 \\ 0 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix} $$ 再使第三行进行水平异或: $$ a=\begin{pmatrix} 0 & 0 & 1 \\ 0 & 0 & 1 \\ 0 & 0 & 1 \end{pmatrix} $$ 最后使第三列进行垂直异或即可。

输入格式

第一行,一个整数 $t(1\leq t\leq 1000)$ 表示数据组数。 接下来 $t$ 组,每组开头一个整数 $n(1\leq n\leq 1000)$ 描述了这两个矩阵的大小,接下来给出了两个矩阵。 对于单个测试点内的所有测试数据,$n$ 的总和不超过 $1000$。

输出格式

$t$ 行,每行一个字符串 `YES` 或 `NO`,表示 $a$ 矩阵是否可以经过有限次操作变为 $b$。

说明/提示

The first test case is explained in the statements. In the second test case, the following sequence of operations is suitable: - horizontal xor, $ i=1 $ ; - horizontal xor, $ i=2 $ ; - horizontal xor, $ i=3 $ ; It can be proved that there is no sequence of operations in the third test case so that the matrix $ a $ becomes equal to the matrix $ b $ .