PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000116. Thu thập bảy viên ngọc (Dragon Ball I)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn cities and mm undirected teleporters with nonnegative travel costs. You start in city 11. 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 n,mn,m; then mm undirected edges u,v,wu,v,w; finally exactly seven integers indicating the Dragon Ball locations. Cities are 11-indexed.

Output

Print the minimum total cost or -1.

Subtasks

  • Subtask 1 (40 points): 1≤n≤101\le n\le 10, 1≤m≤201\le m\le 20, 0≤w≤300\le w\le 30. All input conditions remain in force.

  • Subtask 2 (60 points): 1≤n,m≤2000001\le n,m\le 200000, 0≤w≤100000\le w\le 10000. 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.