当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1842:Parking

题目描述
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.
输入解释
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.
输出解释
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).
输入样例
6 3 2
1 4
1 6
0
1 5
2 2 3
0
4 5
输出样例
4

该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 Croatia OI 2002

源链接: POJ-1842

最后修改于 2020-10-29T06:15:35+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 30000