아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Excursion to Porvoo

시간 제한5초메모리 제한1024 MB

요약
각 차량 무게마다 1번 도시에서 n번 도시까지 이동하는 최소 시간을 구한다. 도로마다 길이와 무게 제한이 있다.
난이도

보통10점 중 6점

유형
정렬, 유니온 파인드, 완전 탐색, 구현
정답자
아직 제출이 없습니다

문제

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 nn 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 3131.

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 nn and mm (2≤n≤105,n−1≤m≤105)(2 \leq n \leq 10^5, n - 1 \leq m \leq 10^5), the number of cities and the number of connections, respectively. The cities are numbered from 11 to nn, Tampere is city 11, and Porvoo is city nn.
  • mm lines, each containing three integers ii, dd and cc (1≤i<n,1≤d≤104,1≤c≤106)(1 \leq i < n, 1 \leq d \leq 10^4, 1 \leq c \leq 10^6), which each describe a connection between city ii and city i+1i + 1 which takes dd minutes to traverse and can can be used by vehicles of weight cc kilograms or less.
  • One integer qq (1≤q≤105)(1 \leq q \leq 10^5), the number of cars that Alice has collected.
  • qq lines, where the iith line contains one integer w_iw\_i (1≤w_i≤106)(1 \leq w\_i \leq 10^6), the weight of the iith car in kilograms.

There is at least one connection from city ii to city i+1i+1 for each ii (1≤i<n1 \le i < n).

출력

Output qq lines, where the iith line describes the shortest time in minutes Alice needs to drive to get from Tampere to Porvoo with the iith car. If there is no feasible path for the iith car, output impossible.

예제3

  1. 예제 1

    입력
    2 2
    1 100 300
    1 1 30
    5
    400
    500
    300
    20
    1
    
    예상 출력
    impossible
    impossible
    100
    1
    1
    
  2. 예제 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. 예제 3

    입력
    2 3
    1 3 3
    1 4 2
    1 2 1
    3
    1
    3
    2
    
    예상 출력
    2
    3
    3