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

#FW0000111. Chuyến du lịch của Joisino (joisino’s travel)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chuyến du lịch của Joisino (joisino’s travel)

joisino’s travel

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

An undirected weighted road network has nn cities. Choose an order to visit rr designated cities. Flying to the first one and back from the last one costs no road distance; travel between successive designated cities must use roads. Minimize total road distance.

Input

First line n,m,rn,m,r, then rr designated cities, then mm roads u,v,wu,v,w.

Output

Print minimum total road distance.

Subtasks

  • Subtask 1 (40 points): 3≤n≤6,  2≤r≤43\le n\le 6,\;2\le r\le 4. All input-format and graph conditions above apply.

  • Subtask 2 (60 points): 3≤n≤16,  2≤r≤83\le n\le 16,\;2\le r\le 8. All input-format and graph conditions above apply.

Examples

Input

3 2 2
1 3
1 2 2
2 3 3

Output

5

Explanation

The required cities are 1 and 3. Their shortest route passes through city 2 with distance 2+3=52+3=5. Reversing their visit order has the same cost.