Time limit
1s
Memory limit
128 MB
Sua found a treasure map. The map is an N × M grid, and each cell is either sea or part of an island. The map also marks the treasure, a pirate ship, and the current position of Sua.
Sua must choose a route that starts at the current position and ends at the treasure. On each move, Sua moves one cell up, down, left, or right, and cannot enter an island cell.
The pirate moves in the same way. Each turn, Sua moves first, and then the pirate either moves one cell or stays in place. After each turn, apply the following rules.
Determine whether there is a route that lets Sua obtain the treasure without being caught, no matter how the pirate moves.
The first line contains N and M. The next N lines contain the treasure map. Each line consists of M characters.
V, Y, and T each appear exactly once.
Constraint: 1 ≤ N, M ≤ 700
Print YES if Sua can obtain the treasure, and print NO otherwise.
In the first visible test case, moving down, down, down, right, right, right, and down reaches the treasure.