Pinely Round 5 (Div. 1 + Div. 2)
B
Make Connected
Codeforces
1700
原题
← AC →
翻译中…

You are given an $n \times n$ grid where some cells are colored black, and the rest are white. You may paint some of the white cells black to achieve the following conditions:

翻译中…
  1. There is at least one black cell.
  2. All black cells must be orthogonally connected, that is, it should be possible to go from any black cell to any other by crossing several vertical or horizontal cell borders while visiting only black cells. You can't go directly through the corner of a cell.
  3. There are no three consecutive black cells aligned vertically or horizontally.
翻译中…

You can't paint black cells white.

翻译中…

Determine whether it is possible to paint some white cells black in order to satisfy all the conditions.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.

翻译中…

The first line contains an integer $n$ ($1 \leq n \leq 100$) — the size of the grid.

翻译中…

The following $n$ lines contain $n$ characters each — the grid description, where each character represents a cell:

翻译中…
  • . — a white cell;
  • # — a black cell.
翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2000$.

翻译中…

Output

翻译中…

For each test case, print "YES" if it is possible to paint some white cells black to satisfy all the conditions, and "NO" otherwise.

翻译中…

You may print each letter in any case (uppercase or lowercase). For example, the strings "yEs", "yes", "Yes", and "YES" will all be recognized as a positive answer.

翻译中…

Note

翻译中…

In the first test case, there are no black cells, so we must paint one cell black.

翻译中…

In the second and third test cases, the grid satisfies all the conditions from the very beginning.

翻译中…

In the fourth test case, one of the possible solutions is:

翻译中…

##.
.##
..#

翻译中…

In the fifth test case, the grid violates the "No three consecutive black cells should be aligned vertically or horizontally" condition from the very beginning, so there is no solution.

翻译中…

In the sixth test case, it can be shown that it is impossible to achieve a connected grid without violating the condition about three consecutive black cells.

翻译中…

样例

Input #1
11
1
.
1
#
3
.##
.##
...
3
#..
.#.
..#
3
###
...
...
3
#.#
...
.#.
4
####
#..#
#..#
####
3
..#
...
.#.
3
..#
#..
...
5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#
5
...#.
...#.
.....
##...
.....
Output #1
YES
YES
YES
YES
NO
NO
NO
YES
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
2161B
时间限制
1.5 s
内存限制
512 MB
标签
暴力
模拟

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