PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000009. Chi phí di chuyển (Travelling Cost)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chi phí di chuyển (Travelling Cost)
Travelling Cost
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Locations through are connected by bidirectional roads with positive costs. Answer shortest costs from one fixed start to multiple destinations.
Input
; roads ; source ; ; then destinations.
Output
Print shortest costs, or NO PATH when unreachable.
Subtasks
- Subtask 1 (40 points): at most distinct road endpoints; ; ; ; .
- Subtask 2 (60 points): ; ; ; .
Examples
Input
7
0 1 4
0 3 8
1 4 1
1 2 2
4 2 3
2 5 3
3 4 2
0
4
1
4
5
7
Output
4
5
9
NO PATH
Explanation
From location 0, shortest costs to 1, 4, 5 are respectively , and . Location 7 cannot be reached.