This page is still under construction.

Parts of this page are still being built. What you see may change.

Hotel Booking

Time limit1sMemory limit128 MB

Summary
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 nn 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 nn (2≤n≤100002 \le n \le 10000), the number of cities considered when planning the route. Cities are numbered from 1 to nn; city 1 is the starting city and city nn is the destination.

The next line contains an integer hh followed by the city numbers c1,c2,…,chc_1, c_2, \dots, c_h where the chain's hotels are located (0≤h≤min⁡(n,100)0 \le h \le \min(n, 100)).

The third line contains an integer mm (1≤m≤1051 \le m \le 10^5), the number of roads. Each of the following mm lines describes one road with three integers a,b,ta, b, t (1≤a,b≤n1 \le a, b \le n and 1≤t≤6001 \le t \le 600): the road connects cities aa and bb, and a driver needs tt 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 n=0n = 0.

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 nn. If no route exists in which the driver drives at most 10 hours (600 minutes) per day, print −1-1 instead.

Examples1

  1. Example 1

    Input
    6
    3 2 5 3
    8
    1 2 400
    3 2 80
    3 4 301
    4 5 290
    5 6 139
    1 3 375
    2 5 462
    4 6 300
    3
    0
    2
    1 2 371
    2 3 230
    0
    
    Expected output
    2
    -1