编程介的小学生 2017-04-09 07:50 采纳率: 20.5%
浏览 805
已采纳

Maze

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?

Input

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)

Output

For each case print Yes if Mr Maze could reach the correct exit.
Print No otherwise.

Sample Input

3
1 1
1 2
1 2
4
1 2
1 1
1 2
1 4
Sample Output

Yes
No

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-04-23 15:46
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试