PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000002. Thành phố ánh sáng chói lòa (Floyd: City of Blinding Lights)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Thành phố ánh sáng chói lòa (Floyd: City of Blinding Lights)
Floyd: City of Blinding Lights
Source: HackerRank
Version: Phuoc Hung OJ Extended
Problem Statement
A directed weighted graph is given. Answer the shortest-path distance for each ordered query; return when unreachable.
Input
; directed edges; ; queries.
Output
Print the answer to every query on its own line.
Subtasks
- Subtask 1 (40 points): , ; ; ; ; ; .
- Subtask 2 (60 points): ; ; ; ; .
Examples
Input
3 3
1 2 5
2 3 2
1 3 10
3
1 3
3 1
2 2
Output
7
-1
0
Explanation
The route costs versus directly. No route goes from back to ; the distance from to itself is zero.