eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Long Distance Taxi

Long Distance Taxi

A taxi driver, Nakamura, was so delighted because he got a passenger who wanted to go to a city thousands of kilometers away. However, he had a problem. As you may know, most taxis in Japan run on lique ed petroleum gas (LPG) because it is cheaper than gasoline. There are more than \textbf{50,000} gas stations in the country, but less than one percent of them sell LPG. Although the LPG tank of his car was full, the tank capacity is limited and his car runs \textbf{10} kilometer per liter, so he may not be able to get to the destination without lling the tank on the way. He knew all the locations of LPG stations. Your task is to write a program that nds the best way from the current location to the destination without running out of gas. \InputFile The input consists of several datasets, and each dataset is in the following format. \textbf{N M capsrc destc1;1 c1;2 d1c2;1 c2;2 d2...cN;1 cN;2 dNs1s2...sM} The fi rst line of a dataset contains three integers (\textbf{N}, \textbf{M}, \textbf{cap}), where \textbf{N} is the number of roads (\textbf{1} ≤ \textbf{N} ≤ \textbf{3000}), \textbf{M} is the number of LPG stations (\textbf{1} ≤ \textbf{M} ≤ \textbf{300}), and cap is the tank capacity (\textbf{1} ≤ \textbf{cap} ≤ \textbf{200}) in liter. The next line contains the name of the current city (\textit{src}) and the name of the destination city (\textit{dest}). The destination city is always different from the current city. The following \textbf{N} lines describe roads that connect cities. The road \textbf{i} (\textbf{1} ≤ \textbf{i} ≤ \textbf{N}) connects two different cities \textbf{c_\{i,1\}} and \textbf{c_\{i,2\}} with an integer distance \textbf{d_i} (\textbf{0} < \textbf{d_i} ≤ \textbf{2000}) in kilometer, and he can go from either city to the other. You can assume that no two different roads connect the same pair of cities. The columns are separated by a single space. The next \textbf{M} lines (\textbf{s_1}, \textbf{s_2}, ..., \textbf{s_M}) indicate the names of the cities with LPG station. You can assume that a city with LPG station has at least one road. The name of a city has no more than \textbf{15} characters. Only English alphabet ('\textbf{A}' to '\textbf{Z}' and '\textbf{a}' to '\textbf{z}', case sensitive) is allowed for the name. A line with three zeros terminates the input. \OutputFile For each dataset, output a line containing the length (in kilometer) of the shortest possible journey from the current city to the destination city. If Nakamura cannot reach the destination, output "\textbf{-1}" (without quotation marks). You must not output any other characters. The actual tank capacity is usually a little bit larger than that on the speci cation sheet, so you can assume that he can reach a city even when the remaining amount of the gas becomes exactly zero. In addition, you can always ll the tank at the destination so you do not have to worry about the return trip.
Лимит времени 30 секунд
Лимит использования памяти 64 MiB
Входные данные #1
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
Выходные данные #1
846
-1
Источник Asia Regional Fukuoka, Japan, 2011-11-13