Logo
(追記) (追記ここまで)

24470번 - Autobus 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB57252251.163%

문제

In a country there are $n$ cities. The cities are connected by $m$ bus routes, where the $i$-th route starts in city $a_i,ドル ends in city $b_i$ and takes $t_i$ minutes.

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

Help her answer $q$ questions of the form ‘What is the shortest travel time to get from city $c_j$ to city $d_j$ (using at most $k$ different bus routes)?’.

입력

The first line contains two positive integers $n$ and $m$ (2ドル ≤ n ≤ 70,ドル 1ドル ≤ m ≤ 10^6$), the number of cities and the number of bus routes.

The $i$-th of the next $m$ lines contains positive integers $a_i,ドル $b_i$ and $t_i$ (1ドル ≤ a_i , b_i ≤ n,ドル 1ドル ≤ t_i ≤ 10^6$), the terminal cities and the travel time of the $i$-th bus route.

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

The $j$-th of the next $q$ lines contains positive integers $c_j$ and $d_j$ (1ドル ≤ c_j , d_j ≤ n$), the cities from the $j$-th query.

출력

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

제한

서브태스크

번호배점제한
115

$k ≤ n ≤ 7$

215

$k ≤ 3$

315

$k ≤ n$

415

No additional constraints.

예제 입력 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

예제 출력 1

10
-1
0

예제 입력 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

예제 출력 2

6
4
0

예제 입력 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

3
4
0

힌트

Clarification of the examples:

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

출처

Contest > Croatian Open Competition in Informatics > COCI 2021/2022 > Contest #4 2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /