Time Limit: 10 Seconds
Memory Limit: 32768 KB
There is a maze that has n entrances in the top while n exits in the other side.
In this maze, Mr Maze can go down, go left, go right but he can't go up.
What's more, he have to turn left or right if he could.
Both entrances and exits will be numbered from left to right starting by 1.
Now, Mr Maze is at No.a extrance and he wants to go to No.b exit.
And he has only one chance to go straight when he has to turn.
Of course he can only do this when he could go forward.
Can he get to the exit?
The input contains multiple test cases (no more than 30).
The first line only contains an integer n. (1 <= n <= 1000)
Then follow n-1 lines.
The i+1-th line describes the horizontal lines which begin with the i-th vertical line.
Each line begin with an integer m which means there are m horizontal lines. (1 <= m <= 1000)
Then m integers follow. Each integer describes a horizontal line's distance from the top.
All the integer will be larger than 0 and less than 100000000.
And there won't be two horizontal lines having same distance if they begin or end with same vertical lines.
The last line contains two integers a and b. (1 <= a,b <=n)
For each case print Yes if Mr Maze could reach the correct exit.
Print No otherwise.
Author: MIN, Zhechen
Source: ZOJ Monthly, July 2009