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

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

Autobus

시간 제한1초메모리 제한512 MB

요약
가중치가 있는 방향 그래프에서 최대 k개의 간선을 사용해 두 도시 사이를 이동하는 최단 시간을 묻는 질의에 답한다.
난이도

보통10점 중 7점

유형
그래프, 최단 경로, 행렬, 동적 계획법
정답자
아직 제출이 없습니다

문제

In a country there are nn cities. The cities are connected by mm bus routes, where the ii-th route starts in city a_ia\_i, ends in city b_ib\_i and takes t_it\_i minutes.

Ema loves to travel, but doesn’t like transferring between buses. On her trip she wants to use at most kk different bus routes.

Help her answer qq questions of the form ‘What is the shortest travel time to get from city c_jc\_j to city d_jd\_j (using at most kk different bus routes)?’.

입력

The first line contains two positive integers nn and mm (2≤n≤702 ≤ n ≤ 70, 1≤m≤1061 ≤ m ≤ 10^6), the number of cities and the number of bus routes.

The ii-th of the next mm lines contains positive integers a_ia\_i, b_ib\_i and t_it\_i (1≤a_i,b_i≤n1 ≤ a\_i , b\_i ≤ n, 1≤t_i≤1061 ≤ t\_i ≤ 10^6), the terminal cities and the travel time of the ii-th bus route.

The next line contains two positive integers kk and qq (1≤k≤1091 ≤ k ≤ 10^9, 1≤q≤n21 ≤ q ≤ n^2), the maximum number of used routes and the number of queries.

The jj-th of the next qq lines contains positive integers c_jc\_j and d_jd\_j (1≤c_j,d_j≤n1 ≤ c\_j , d\_j ≤ n), the cities from the jj-th query.

출력

Print qq lines. In the jj-th line print the shortest travel time from the jj-th query, or -1 if there is no trip that satisfies the requirements.

힌트

Clarification of the examples:

The answer to the first query from each example is marked on the graph.

예제3

  1. 예제 1

    입력
    4 7
    1 2 1
    1 4 10
    2 3 1
    2 4 5
    3 2 2
    3 4 1
    4 3 2
    1 3
    1 4
    4 2
    3 3
    
    예상 출력
    10
    -1
    0
    
  2. 예제 2

    입력
    4 7
    1 2 1
    1 4 10
    2 3 1
    2 4 5
    3 2 2
    3 4 1
    4 3 2
    2 3
    1 4
    4 2
    3 3
    
    예상 출력
    6
    4
    0
    
  3. 예제 3

    입력
    4 7
    1 2 1
    1 4 10
    2 3 1
    2 4 5
    3 2 2
    3 4 1
    4 3 2
    3 3
    1 4
    4 2
    3 3
    
    예상 출력
    3
    4
    0