Hex
In the game "Hex," players compete on a rhombus-shaped board consisting of N rows and N hexagons per row, where N is a positive integer not exceeding 20. The illustration shows the board configuration for N=5. The game features two players: the first player uses white pieces, while the second player uses black pieces. During each turn, a player places one piece on any unoccupied hexagon. The objective for the white player is to create a continuous path of white pieces connecting the top and bottom edges of the board. Conversely, the black player's goal is to connect the left and right edges with a path of black pieces. Movement is only possible through the sides of adjacent hexagons.
Your task is to write a program that determines if the white player has won in the current board position.
Input
The first line contains the integer N. The following N lines each contain a string of N characters. A character 'W' represents a hexagon occupied by a white piece, 'B' represents a black piece, and 'E' denotes an empty hexagon.
Output
Output YES if the white player has won by forming a path connecting the top and bottom rows. Otherwise, output NO.