#FW0000116. Thu thập bảy viên ngọc (Dragon Ball I)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Thu thập bảy viên ngọc (Dragon Ball I)
Dragon Ball I
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A graph contains cities and undirected teleporters with nonnegative travel costs. You start in city . Seven Dragon Balls are at the seven listed city indices, possibly with repetitions. Visiting a city collects every ball there. You need not return home. Find the minimum cost to collect all seven balls; print -1 if it cannot be done.
Input
First line ; then undirected edges ; finally exactly seven integers indicating the Dragon Ball locations. Cities are -indexed.
Output
Print the minimum total cost or -1.
Subtasks
-
Subtask 1 (40 points): , , . All input conditions remain in force.
-
Subtask 2 (60 points): , . All input conditions remain in force.
Examples
Input
10 9
1 2 1
2 3 1
3 4 1
4 5 1
5 6 1
6 7 1
7 8 1
8 9 1
9 10 1
1 2 3 4 5 6 7
Output
6
Explanation
Walking along cities 1,2,...,7 collects the seven balls at a total cost of 6.