, , BFS .
BFS , , :
1. Enqueue every point that is accessible (not a piece of wall, and not visited) and connected to the current point.
2. Dequeue current point and mark it as VISITED.
, BFS , .
, BFS , "":
-, , "".
.
(, 1 * 2, ).
00: The point can't be accessed, neither the object is horizontal nor vertical.
10: The point can be accessed if the object is horizontal
01: The point can be accessed if the object is vertical
11: The point can be accessed if the object is either horizontal or vertical
, :

00,

, .
, , " " :
connected . :
---------
| 01| 10|
|---|---|
| 10| |
--------- (Not Connected from top-left to either top-right or bottom-left)
---------
| 11| 10|
|---|---|
| 01| |
--------- (Connected from top-left to both top-right and bottom-left)
---------
| 10| 10|
|---|---|
| 01| |
--------- (Connected from top-left to top-right, but not connected to bottom-left)
, . BFS 2- . Dequeue, , connected , , BFS.
, , , . , .
