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

20610번 - Walking Plan 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB1222100.000%

문제

There are $n$ intersections in Bytetown, connected with $m$ one-way streets. These intersections are labeled by 1,2,ドル\dots,n$. Little Q likes sport walking very much, he plans to walk for $q$ days. On the $i$-th day, Little Q plans to start walking at the $s_i$-th intersection, move along a street at least $k_i$ times, and finally arrive to the $t_i$-th intersection. Note that $k_i$ is the required number of moves, not streets: it is allowed to use any street more than once.

Little Q's smartphone will record his walking route. Little Q cares more about statistics than about staying healthy. So he wants to minimize the total walking length on each day. Please write a program to help him find the best route.

입력

The first line contains a single integer $T$ (1ドル \leq T \leq 10$), the number of test cases. For each test case:

The first line contains two integers $n$ and $m$ (2ドル \leq n \leq 50,ドル 1ドル \leq m \leq 10,000円$) denoting the number of intersections and one-way streets.

Each of the next $m$ lines contains three integers $u_i,ドル $v_i,ドル $w_i$ (1ドル \leq u_i, v_i \leq n,ドル $u_i \neq v_i,ドル 1ドル \leq w_i \leq 10,000円$) denoting a one-way street from intersection $u_i$ to intersection $v_i$ with length $w_i$.

In the next line, there is an integer $q$ (1ドル \leq q \leq 100,000円$) denoting the number of days.

Each of the next $q$ lines contains three integers $s_i,ドル $t_i,ドル $k_i$ (1ドル \leq s_i, t_i \leq n,ドル 1ドル \leq k_i \leq 10,000円$) describing the walking plan.

출력

For each walking plan, print a line containing a single integer: the minimum total walking length. If there is no solution, please print "-1".

제한

예제 입력 1

2
3 3
1 2 1
2 3 10
3 1 100
3
1 1 1
1 2 1
1 3 1
2 1
1 2 1
1
2 1 1

예제 출력 1

111
1
11
-1

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2020 > Day 3: Songyang Chen Contest 3 J번

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

출처

대학교 대회

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

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