This page is still under construction.

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

Long Distance Taxi

Time limit1sMemory limit128 MB

Summary
Given an undirected weighted graph, a tank range, and a set of refueling cities, find the shortest route from src to dest that never runs out of gas.
Level

Medium7 of 10

Topics
Graph, Shortest path, Greedy, Binary search
Solved
No attempts yet

Problem

A taxi driver named Nakamura is thrilled to pick up a passenger heading to a city thousands of kilometers away. But there is a catch. Like most taxis in the country, his car runs on liquefied petroleum gas (LPG) because it is cheaper than gasoline. There are more than 50,000 gas stations, yet fewer than one percent of them sell LPG. His LPG tank starts out full, but its capacity is limited and the car travels 10 kilometers per liter, so he may not reach the destination without refilling along the way. He knows the location of every LPG station.

Write a program that finds the shortest possible route from the starting city to the destination without ever running out of gas. With a tank capacity of capcap liters, a full tank lets the car travel at most 10×cap10 \times cap kilometers before it must refuel at an LPG station.

Input

The input consists of several datasets. Each dataset has the following format:

N M cap
src dest
c(1,1) c(1,2) d(1)
c(2,1) c(2,2) d(2)
...
c(N,1) c(N,2) d(N)
s(1)
s(2)
...
s(M)

The first line contains three integers NN, MM, and capcap, where NN (1≤N≤30001 \le N \le 3000) is the number of roads, MM (1≤M≤3001 \le M \le 300) is the number of LPG stations, and capcap (1≤cap≤2001 \le cap \le 200) is the tank capacity in liters. The next line contains the name of the starting city srcsrc and the destination city destdest; the destination is always different from the start. Each of the next NN lines describes a road: road ii (1≤i≤N1 \le i \le N) connects two distinct cities ci,1c_{i,1} and ci,2c_{i,2} with an integer distance did_i (0<di≤20000 < d_i \le 2000) in kilometers, and it can be traveled in either direction. No two distinct roads connect the same pair of cities, and columns are separated by a single space. The following MM lines list the names of the cities that have an LPG station; every such city has at least one road.

A city name has at most 15 characters, using only English letters ('A'-'Z' and 'a'-'z', case sensitive).

A line containing three zeros terminates the input.

Output

For each dataset, print a single line with the length in kilometers of the shortest possible journey from the starting city to the destination. If Nakamura cannot reach the destination, print −1-1. Do not print any other characters.

The real tank capacity is usually slightly larger than the specification, so he can reach a city even when the remaining gas becomes exactly zero. He can also always refill at the destination, so the return trip does not matter.

Examples1

  1. Example 1

    Input
    6 3 34
    Tokyo Kyoto
    Tokyo Niigata 335
    Tokyo Shizuoka 174
    Shizuoka Nagoya 176
    Nagoya Kyoto 195
    Toyama Niigata 215
    Toyama Kyoto 296
    Nagoya
    Niigata
    Toyama
    6 3 30
    Tokyo Kyoto
    Tokyo Niigata 335
    Tokyo Shizuoka 174
    Shizuoka Nagoya 176
    Nagoya Kyoto 195
    Toyama Niigata 215
    Toyama Kyoto 296
    Nagoya
    Niigata
    Toyama
    0 0 0
    
    Expected output
    846
    -1