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

Full Tank

Full Tank

After going through the receipts from your car trip through Europe this summer, you realised that the gas prices varied between the cities you visited. Maybe you could have saved some money if you were a bit more clever about where you filled your fuel? To help other tourists (and save money yourself next time), you want to write a program for finding the cheapest way to travel between cities, filling your tank on the way. We assume that all cars use one unit of fuel per unit of distance, and start with an empty gas tank. \InputFile The first line of input gives \textbf{1} ≤ \textbf{n} ≤ \textbf{1000} and \textbf{0} ≤ \textbf{m} ≤ \textbf{10000}, the number of cities and roads. Then follows a line with \textbf{n} integers \textbf{1} ≤ \textbf{p_i} ≤ \textbf{100}, where \textbf{p_i} is the fuel price in the \textbf{i}-th city. Then follow \textbf{m} lines with three integers \textbf{0} ≤ \textbf{u}, \textbf{v} < \textbf{n }and \textbf{1} ≤ \textbf{d} ≤ \textbf{100}, telling that there is a road between \textbf{u} and \textbf{v} with length \textbf{d}. Then comes a line with the number \textbf{1} ≤ \textbf{q} ≤ \textbf{100}, giving the number of queries, and \textbf{q} lines with three integers \textbf{1} ≤ \textbf{c} ≤ \textbf{100}, \textbf{s} and \textbf{e}, where \textbf{c} is the fuel capacity of the vehicle, \textbf{s} is the starting city, and \textbf{e} is the goal. \OutputFile For each query, output the price of the cheapest trip from \textbf{s} to \textbf{e} using a car with the given capacity, or impossible if there is no way of getting from \textbf{s} to \textbf{e} with the given car.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
5 5
10 10 20 12 13
0 1 9
0 2 8
1 2 1
1 3 11
2 3 7
2
10 0 3
20 1 4
Вихідні дані #1
170
impossible
Джерело 2007 Nordic Collegiate Programming Contest, 6 Октября, Задача F