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

#FW0000103. Nguyên liệu làm bánh (Ingredients)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Nguyên liệu làm bánh (Ingredients)

Ingredients

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

Two friends start in different cities. There are ss stores each supplying a different needed ingredient. Every store must be visited by at least one friend, who need not return home. Minimize the sum of travel distances over both friends in the undirected road network.

Input

First n,mn,m and mm undirected roads u,v,wu,v,w with zero-based vertices. Then ss and the ss store IDs, followed by two starting cities a,ba,b.

Output

Print the minimum total distance or -1.

Subtasks

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

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

Examples

Input

3 2
0 2 3
1 2 4
1
2
0 1

Output

3

Explanation

The sole ingredient is at city 2. The first friend can reach it from city 0 at cost 3, versus cost 4 from city 1. Only one needs to visit and no return is needed, giving min⁡(3,4)=3\min(3,4)=3.