编程介的小学生 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 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号