Labyrinth


Submit solution

Points: 7 (partial)
Time limit: 2.0s
Memory limit: 512M

Problem type

You are given a map of a labyrinth, and your task is to determine a path from start to end. You can walk left, right, up and down.

Input

The first input line has two integers \(n\) and \(m\): the height and width of the map. Then there are n lines of m characters describing the labyrinth. Each character is . (floor), # (wall), \(A\) (start), or \(B\) (end). There is exactly one \(A\) and one \(B\) in the input.

Output

Print "YES", if there is a path, and "NO" otherwise.

Constraints

\(1 \le n,m \le 1000\)

Sample Input:

5 8
########
#.A#...#
#.##.#B#
#......#
########

Sample Output:

YES

Comments

There are no comments at the moment.