#C3932. Single Cluster of Trees
Single Cluster of Trees
Single Cluster of Trees
You are given a forest grid with T representing trees and . representing empty spaces. Your task is to determine whether the forest has exactly one contiguous cluster of trees. Two trees are considered part of the same cluster if they are adjacent horizontally or vertically.
Note: The grid is provided as n lines each containing a row of characters. The input begins with an integer n which indicates the number of rows. When n = 0, it indicates the end of the input.
The problem can be formally defined as follows. Let \(G\) be a grid of size \(n \times m\) where \(G_{i,j}\) is either 'T' (tree) or '.' (empty). We say that two cells \(G_{i,j}\) and \(G_{k,l}\) are connected if \(|i-k| + |j-l| = 1\). A cluster is a maximal set of tree cells where each cell is reachable from any other through connected tree cells. Output "Yes" if there is exactly one cluster of trees; otherwise, output "No".
inputFormat
The input consists of multiple test cases. Each test case begins with an integer n (\(1 \leq n \leq 100\)), indicating the number of rows in the forest grid. The following n lines each contain a string representing a row of the forest. The input terminates with a test case where n = 0, which should not be processed.
All input is provided through standard input (stdin).
outputFormat
For each test case, output a single line containing "Yes" if the grid contains exactly one cluster of trees, otherwise output "No".
All output should be written to standard output (stdout).
## sample3
.T.
TTT
.T.
0
Yes
</p>