#P7479. 至曾是英雄的您
至曾是英雄的您
Background
YSGHYYDS
Problem Description
YSGH has an Go board. Initially, each cell is either empty or contains a black stone. It is guaranteed that all black stones are connected.
In Go, the “liberties” of a stone are defined as the set of all empty cells adjacent to it.
Let the cell in row and column be .
Two same-colored stones at and are considered adjacent if , meaning they are in the same connected component.
The “liberties” of a connected component are the union of the liberties of all stones in that component.
A white move is legal if and only if, after placing the stone, either the liberties of the connected component containing that white stone are at least , or the liberties of the black connected component become .
For example, in the figure below, the green cells are all liberties of the black connected component.

Definition of a “living group”: no matter how many consecutive moves the opponent makes, as long as every move is legal, the liberties of that connected component are always at least .
Please determine whether this black connected component is a “living group”.
If it is, output YES; otherwise, output NO.
This problem has multiple test cases.
Input Format
The first line contains a positive integer , the number of test cases.
For each test case:
The first line contains two positive integers , meaning the board size is .
Then follow lines, each a string of length . The -th character of the -th line indicates whether there is a stone at position . . means empty, and * means a black stone.
Output Format
If the black group is “living”, output YES; otherwise, output NO.
3
3 5
.*.*.
.***.
.....
2 5
.*.*.
.***.
6 5
.*...
.***.
**.**
*...*
**.**
*****
NO
YES
NO
1
1 3
.*.
YES
Hint
[Sample Explanation #1]
Test case 1:
White plays in order, which makes the liberties of the black connected component become .
Let @ denote white stones. Then the final position is:
@*@*@
@***@
.@@@.
Test case 2:
For example, if White first plays , then White will never be able to play at and afterward, causing the liberties of the black group to always be at least . Therefore, the black group is “living”.
Test case 3:
A final position that makes the liberties of the black connected component equal to :
@*@@.
@***@
**@**
*@.@*
**@**
*****
[Constraints]
This problem uses bundled testdata.
For of the data: , . Each cell of the initial board is either . or *, and there is at least one ., and at least one *. It is guaranteed that black stones are connected. The sum of over each test point is at most .
- Subtask 1 (9 points): .
- Subtask 2 (10 points): , .
- Subtask 3 (16 points): the number of
.is at most , , . - Subtask 4 (24 points): the number of
.is at most , , . - Subtask 5 (15 points): , and all boundary cells of the input position are
.. That is, , if , then must be empty. - Subtask 6 (26 points): no special constraints.
P.S. Froggy and uyom are both (amateur 4-dan brothers who have not played for a long time), feel free to find us and beat us up.
Translated by ChatGPT 5