#K54437. Reach the Treasure

    ID: 29753 Type: Default 1000ms 256MiB

Reach the Treasure

Reach the Treasure

You are given an n × m grid where each cell contains one of the following characters:

  • . representing an open cell
  • T representing an obstacle
  • X representing the treasure

Your task is to determine if there is a path from the top-left corner of the grid (cell (1,1)) to any cell containing the treasure. You can move up, down, left, or right. Moving into a cell marked with T is not allowed. If the starting cell is the treasure, then the answer is automatically "YES".

If there exists a valid path, output "YES"; otherwise, output "NO".

inputFormat

The first line contains two integers n and m representing the number of rows and columns of the grid respectively. This is followed by n lines, each containing a string of length m composed of characters '.', 'T', or 'X'.

outputFormat

Print a single line containing "YES" if there is a path from the top-left cell to a cell containing 'X'. Otherwise, print "NO".## sample

4 4
....
T.TT
..T.
...X
YES