Codeforces Round 777 (Div. 2)
B
Madoka and the Elegant Gift
Codeforces
1200
原题
← AC →
翻译中…

Madoka's father just reached $1$ million subscribers on Mathub! So the website decided to send him a personalized award — The Mathhub's Bit Button!

翻译中…

The Bit Button is a rectangular table with $n$ rows and $m$ columns with $0$ or $1$ in each cell. After exploring the table Madoka found out that:

翻译中…
  • A subrectangle $A$ is contained in a subrectangle $B$ if there's no cell contained in $A$ but not contained in $B$.
  • Two subrectangles intersect if there is a cell contained in both of them.
  • A subrectangle is called black if there's no cell with value $0$ inside it.
  • A subrectangle is called nice if it's black and it's not contained in another black subrectangle.
  • The table is called elegant if there are no two nice intersecting subrectangles.
翻译中…

For example, in the first illustration the red subrectangle is nice, but in the second one it's not, because it's contained in the purple subrectangle.

翻译中…

image

翻译中…

Help Madoka to determine whether the table is elegant.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 200$) — the number of test cases. Description of the test cases follows.

翻译中…

The first line of each test case contains two positive integers $n, m$ ($1 \le n, m \le 100$).

翻译中…

The next $n$ lines contain strings of length $m$ consisting of zeros and ones — the description of the table.

翻译中…

It is guaranteed that the sum of the values of $n$ and the sum of the values of $m$ for all test cases do not exceed $777$.

翻译中…

Output

翻译中…

For each test case print "YES" if its table is elegant or print "NO" otherwise.

翻译中…

You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).

翻译中…

Note

翻译中…

In the second test case the table is not elegant, because the red and the purple subrectangles are nice and intersect.

翻译中…

image

翻译中…

In the fourth test case the table is not elegant, because the red and the purple subrectangles are nice and intersect.

翻译中…

image

翻译中…

样例

Input #1
5
3 3
100
011
011
3 3
110
111
110
1 5
01111
4 5
11111
01010
01000
01000
3 2
11
00
11
Output #1
YES
NO
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
1647B
时间限制
1 s
内存限制
256 MB
标签
暴力
构造
图论
模拟

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