영어 원문입니다. 원문의 수식·표를 글자로 옮겨 모양이 다를 수 있습니다. 정확한 내용은 원문 페이지에서 확인하세요. 원문 페이지 열기 (새 창)
시간 제한 1초 · 메모리 제한 512 MB
Problem
There are n cities and m roads between them. Your task is to process q queries where you have to determine the length of the shortest route between two given cities.
Input
The first input line has three integers n, m and q: the number of cities, roads, and queries.
Then, there are m lines describing the roads. Each line has three integers a, b and c: there is a road between cities a and b whose length is c. All roads are two-way roads.
Finally, there are q lines describing the queries. Each line has two integers a and b: determine the length of the shortest route between cities a and b.
Output
Print the length of the shortest route for each query. If there is no route, print -1 instead.
Constraints
- 1 ≤ n ≤ 500
- 1 ≤ m ≤ n^2
- 1 ≤ q ≤ 10^5
- 1 ≤ a,b ≤ n
- 1 ≤ c ≤ 10^9
예제
예제 1
4 3 5 1 2 5 1 3 9 2 3 3 1 2 2 1 1 3 1 4 3 2
5 5 8 -1 3