PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000098. Mua sắm và đường đi tối ưu (Shopping)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Mua sắm và đường đi tối ưu (Shopping)
Shopping
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
An undirected graph has intersections indexed from . Home is node and a set of shops must be visited. Find the shortest route that starts at home, visits every shop and returns home.
Input
First , then roads using zero-based IDs; then and shop vertices.
Output
Print the minimum total distance or -1 if impossible.
Subtasks
-
Subtask 1 (40 points): . All input-format and graph conditions above apply.
-
Subtask 2 (60 points): . All input-format and graph conditions above apply.
Examples
Input
2 1
0 1 4
1
1
Output
8
Explanation
Go from home 0 to store 1 at distance 4 and return along the same road at distance 4. The round trip costs .