Codeforces Round 168 (Div. 2)
B
Convex Shape
Codeforces
1700
原题
← AC →
翻译中…

Consider an $*n* × *m*$ grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the path. In the figure below, the left grid is convex while the right one is not convex, because there exist two cells which need more than one time to change direction in their path.

翻译中…

image

翻译中…

You're given a painted grid in the input. Tell Lenny if the grid is convex or not.

翻译中…

Input

翻译中…

The first line of the input contains two integers $*n*$ and $*m*$ $(1 ≤ *n*, *m* ≤ 50)$ — the size of the grid. Each of the next $*n*$ lines contains $*m*$ characters "B" or "W". Character "B" denotes a black cell of the grid and "W" denotes a white cell of the grid.

翻译中…

It's guaranteed that the grid has at least one black cell.

翻译中…

Output

翻译中…

On the only line of the output print "YES" if the grid is convex, otherwise print "NO". Do not print quotes.

翻译中…

样例

Input #1
3 4
WWBW
BWWW
WWWB
Output #1
NO
InputCopy OutputCopy
Input #2
3 1
B
B
W
Output #2
YES
InputCopy OutputCopy
题目信息
题号
275B
时间限制
2 s
内存限制
256 MB
标签
构造
模拟

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