Excursion to Porvoo
문제
It is a lovely summer day, and Alice wants to do a day trip. She lives in Tampere, and wants to travel to Porvoo to enjoy the Old Town and the surrounding nature. Alice does not only love travelling, but also planning.
She has created a map of the most beautiful paths to Porvoo. On her trip she needs to visit cities in order, where Tampere is the first city and Porvoo is the last city. The cities are connected by roads, with each road connecting two consecutive cities, and there is always at least one road between each pair of consecutive cities.
When driving from one city to the next, Alice needs to choose which road to take. Some of these roads have a tarmac surface, while others are just gravel roads and some roads have bridges which will not support vehicles that are too heavy. For each road it is known how long it takes to traverse it and what is the maximal weight of vehicles that can safely drive on it.
Figure E.1: Illustration of the second sample input. The red path from Tampere to Porvoo is the optimal choice for a car of weight .
Alice collects many different cars of different weights, but she is not sure yet which car she will use for the day trip. As she wants to enjoy as much time in Porvoo as possible, she wants you to help her find the minimal travel time for each car.
입력
The input consists of:
- Two integers and , the number of cities and the number of connections, respectively. The cities are numbered from to , Tampere is city , and Porvoo is city .
- lines, each containing three integers , and , which each describe a connection between city and city which takes minutes to traverse and can can be used by vehicles of weight kilograms or less.
- One integer , the number of cars that Alice has collected.
- lines, where the th line contains one integer , the weight of the th car in kilograms.
There is at least one connection from city to city for each ().
출력
Output lines, where the th line describes the shortest time in minutes Alice needs to drive to get from Tampere to Porvoo with the th car. If there is no feasible path for the th car, output impossible.
예제
예제 1
2 2 1 100 300 1 1 30 5 400 500 300 20 1
impossible impossible 100 1 1
예제 2
5 7 1 200 30 2 200 31 3 200 32 4 200 33 1 5000 33 2 5000 33 3 5000 33 3 30 31 33
800 5600 15200
예제 3
2 3 1 3 3 1 4 2 1 2 1 3 1 3 2
2 3 3