77 atcoder#ABC229A. [ABC229A] First Grid
[ABC229A] First Grid
Score : points
Problem Statement
We have a grid with horizontal rows and vertical columns. Each of the squares is black or white, and there are at least black squares. The colors of the squares are given to you as strings and , as follows.
- If the -th character of is
#
, the square at the -th row from the top and -th column from the left is black. - If the -th character of is
.
, the square at the -th row from the top and -th column from the left is white.
You can travel between two different black squares if and only if they share a side. Determine whether it is possible to travel from every black square to every black square (directly or indirectly) by only passing black squares.
Constraints
- Each of and is a string with two characters consisting of
#
and.
. - and have two or more
#
s in total.
Input
Input is given from Standard Input in the following format:
Output
If it is possible to travel from every black square to every black square, print Yes
; otherwise, print No
.
##
.#
Yes
It is possible to directly travel between the top-left and top-right black squares and between top-right and bottom-right squares.
These two moves enable us to travel from every black square to every black square, so the answer is Yes
.
.#
#.
No
It is impossible to travel between the top-right and bottom-left black squares, so the answer is No
.