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

28169번 - Shortest Path Query 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB92151317.105%

문제

You will be given a directed acyclic graph with $n$ vertices, labeled by 1,2,ドル\ldots,n$. There are $m$ edges in the graph, each edge is either black or white. It is guaranteed that you can reach every vertex from the 1ドル$-st vertex.

You will be given $q$ queries. In the $i$-th query, you will be given three integers $a_i,ドル $b_i$ and $x_i$. You need to report the length of the shortest path from the 1ドル$-st vertex to the $x_i$-th vertex if we regard the length of each black edge as $a_i$ and regard the length of each white edge as $b_i$.

입력

The first line of the input contains two integers $n$ and $m$ (1ドル \leq n\leq 50,000円,ドル 1ドル\leq m\leq 100,000円$), denoting the number of vertices and the number of directed edges.

In the next $m$ lines, the $i$-th line contains three integers $u_i,ドル $v_i$ and $c_i$ (1ドル\leq u_i<v_i\leq n,ドル $v_i-u_i\leq 1000,ドル 0ドル\leq c_i\leq 1$), describing a directed edge from the $u_i$-th vertex to the $v_i$-th vertex. When $c_i=0,ドル its color is black, and when $c_i=1,ドル its color is white.

The next line contains a single integer $q$ (1ドル \leq q \leq 50,000円$), denoting the number of queries.

Each of the next $q$ lines contains three integers $a_i,ドル $b_i$ and $x_i$ (1ドル\leq a_i,b_i\leq 10,000円,ドル 1ドル\leq x_i\leq n$), denoting a query.

It is guaranteed that you can reach every vertex from the 1ドル$-st vertex.

출력

For each query, print a single line containing an integer, denoting the length of the shortest path.

제한

예제 입력 1

4 4
1 2 0
1 3 1
2 4 0
3 4 1
3
3 5 2
3 2 4
2 3 4

예제 출력 1

3
4
4

힌트

출처

ICPC > Regionals > Asia East Continent > Hong Kong > 2023 ICPC Hong Kong Regional D번

Camp > Petrozavodsk Programming Camp > Winter 2023 > Day 3: 2023 ICPC Asia Hong Kong Regional D번

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

출처

대학교 대회

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

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