#C2929. Path to the Treasure
Path to the Treasure
Path to the Treasure
You are given a grid of size \(m \times n\) where each cell can be one of the following:
- 'S': The starting point.
- 'T': The treasure (target) location.
- '.': A free cell that you can move onto.
- '#': An obstacle cell that you cannot traverse.
Your task is to determine if there exists a path from the starting point 'S' to the treasure 'T'. Movement is allowed in the four cardinal directions (up, down, left, right). It is guaranteed that there is exactly one 'S' and one 'T' in the grid. If a path exists, print YES, otherwise print NO.
Note: The grid is given as \(m\) rows of \(n\) characters.
inputFormat
The input is read from stdin and has the following format:
m n row1 row2 ... rowm
Where:
- m and n are integers representing the number of rows and columns respectively.
- Each of the next m lines contains a string of length n, representing a row of the grid.
outputFormat
Output a single line to stdout containing either YES if there exists a path from 'S' to 'T', or NO otherwise.
## sample3 3
S..
###
.T.
NO
</p>