P28398 [洛谷] [BalticOI 2011 Day1] Treasures and Vikings
提高-
题目描述

Problem Description

You have a treasure map that is arranged into a $N \times M$ grid. A grid square may be either sea or part of an island. In addition, the map shows the treasure and an enemy Viking ship that occupies one (sea) square. Finally, for convenience you have also drawn your own position.

Now you must set up a fixed route to get the treasure. The route must start at your position, end at the treasure, and consist of a sequence of moves. In each move, you can go only to an (horizontally or vertically) adjacent square that is not part of an island. But beware: The Viking ship might follow you, using the same kind of moves! After each of your moves according to your route, the Viking ship may move or not. Your move and the Vikings’ reaction together is called a round.

After every round, the following checks are made:

  • If you are in line with the Viking ship (you are in the same vertical or horizontal line as the Viking ship with only sea between the Viking ship and you), you are dead.
  • If you aren’t dead and at the treasure-spot, you get the treasure.

Write a program that decides whether it is possible to set up a fixed route in advance such that you can get the treasure by following this route and will not get killed by the Vikings – no matter how the Viking ship moves.

Input Format

The first line of input contains two integers $N$ and $M$, the dimensions of the map. Each of the following $N$ lines contain $M$ characters. Each character describes a square in the map, and is either . (sea), I (part of an island), V (the Viking ship), Y (your position), or T (the treasure). Each of V, Y, and T will occur exactly once.

Output Format

The only line of the output must contain the string YES, if it is possible to set up a route to get the treasure, or NO otherwise.

Sample Input and Output

Sample Input #1

5 7
Y.....V
..I....
..IIIII
.......
...T...

Sample Output #1

YES

Sample Input #2

5 7
Y....V.
..I....
..IIIII
.......
...T...

Sample Output #2

NO

Sample Input #3

2 3
.YT
VII

Sample Output #3

NO

Notes

Sample Explanation 1

The route is: go down three times, go right three times, and then go down once more.

Data Range

For $50\%$ of the test cases, $1 \le N, M \le 200$.

For all test cases, $1 \le N, M \le 700$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 7 Y.....V ..I.... ..IIIII ....... ...T...
样例输出
YES