编程介的小学生 2019-09-14 21:46 采纳率: 20.5%
浏览 87

Parking 用程序是如何实现的

Description

An underground garage consists of N parking places located in various floors. Each parking place is denoted by a number between 1 and N, and no two parking places are denoted with the same number. Each parking place is an isolated small room where just one car can be parked. Some of these rooms are directly connected via passages.

A car cannot pass through a parking place occupied by another car. Exit is located in the room #1 where no car can be parked (but any car can pass through it).

There is a unique path between any two parking places. Each pair of successive rooms on a path leading to the exit are located on successive floors of the garage, where the room nearer to the exit is always located in the higher floor.

Ralph Maher had parked his car in the room #P and now he wants to leave the garage. The problem is that there are some other cars parked in some of the rooms he needs to pass through. He has to free every occupied room by pushing a car parked in it to a room in a lower floor. One push is defined as moving a car one floor down from one parking place to another.

Write a program that will determine the minimal number of pushes Ralf needs to do to leave the garage, i.e. to reach the room #1. He will not move his car until path to the exit is completely cleared.
Input

The first line of the input contains three integers N, P and K (2 <= N <= 5000, 2 <= P <= N, 0 <= K <= N-2). Number K denotes the total number of cars parked in the garage excluding Ralph's car, which is parked in the parking place #P. Each of the following N lines contains data about parking places. The line (i+1) contains data about parking places directly connected to the parking place #i located one floor beneath it:
T A1 A2 ... AT
There are T such parking places and A1, A2, ..., AT are their numbers. The last line of the input file contains K integers denoting occupied parking places, not counting Ralph's.
Output

The first and only line of the output should contain minimal number of pushes Ralph need to do to free the path to the exit. If the solution does not exist, the output should contain one line with the text "not solvable" (without quotes).
Sample Input

6 3 2
1 4
1 6
0
1 5
2 2 3
0
4 5
Sample Output

4

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料