跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F2543. Convex Shape

    ID: 2549 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>构造模拟算法思想编程与模拟进阶难度共享题库Codeforces英文题面题目来源题面语言

Convex Shape

题目描述

B. Convex Shape
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

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.

Examples
Input
3 4
WWBW
BWWW
WWWB
Output
NO
Input
3 1
B
B
W
Output
YES

题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 2189 题。保留原作者与原赛事署名。