Hotel Booking
Time limit1sMemory limit128 MB
Given a road network and up to 100 hotel cities, find the minimum number of hotels to book so every driving leg between stays is at most 600 minutes.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, BFS, Greedy
- Solved
- No attempts yet
Problem
A transport company frequently has to deliver goods from one city to another. The company has a special deal with a hotel chain that lets its drivers stay for free in any hotel of the chain. A driver may drive at most 10 hours (600 minutes) per day.
The company wants a route from the starting city to the destination city such that the driver can spend every night in one of the chain's hotels, and such that the driving time from one hotel to the next hotel (or to the destination) never exceeds 10 hours (600 minutes) on any single day. The number of days needed for the delivery should also be minimized.
Equivalently, starting from city 1 and passing through hotels so that every leg takes at most 600 minutes, reach city while minimizing the number of hotels stayed in (the number of hotels that must be booked). The travel time between two points is the length of the shortest route between them in the road network.
Input
The input consists of several test cases. The first line of each test case contains an integer (), the number of cities considered when planning the route. Cities are numbered from 1 to ; city 1 is the starting city and city is the destination.
The next line contains an integer followed by the city numbers where the chain's hotels are located ().
The third line contains an integer (), the number of roads. Each of the following lines describes one road with three integers ( and ): the road connects cities and , and a driver needs minutes to travel from one end to the other. Every road may be used in either direction.
The input is terminated by a test case with .
Output
For each test case, print a single line with the minimum number of hotels the company has to book for a delivery from city 1 to city . If no route exists in which the driver drives at most 10 hours (600 minutes) per day, print instead.