#P7615. Dead-End Detection in a Grid Map

    ID: 20808 Type: Default 1000ms 256MiB

Dead-End Detection in a Grid Map

Dead-End Detection in a Grid Map

You are given an \(R \times C\) grid map. Each cell of the map is represented as follows:

  • . indicates a cell that can be walked on.
  • X indicates an obstacle which cannot be walked on.

A cell is considered a dead-end if among its four neighbors (up, down, left, right) exactly one cell is walkable. Note that cells outside the grid boundaries are not walkable. Formally, if we define a function \[ f(r,c)=\begin{cases}1,&\text{if cell }(r,c) \text{ is walkable (i.e. }'.'\text{)};\\0,&\text{otherwise},\end{cases} \] then a walkable cell at position \((i,j)\) is a dead-end if \[ f(i-1,j)+f(i+1,j)+f(i,j-1)+f(i,j+1)=1. \]

Your task is to determine whether there exists any dead-end cell in the map. If there is at least one dead-end cell, output Yes; otherwise, output No.

inputFormat

The first line of input contains two integers \(R\) and \(C\) representing the number of rows and columns respectively.

The next \(R\) lines each contain a string of length \(C\) consisting of characters . and X, representing the map.

outputFormat

Output a single line containing Yes if there exists at least one dead-end cell on the map, or No otherwise.

sample

3 3
...
...
...
No