Shopping

Time limit3sMemory limit128 MB

Summary
Given weighted roads and up to 10 stores, find the shortest round trip from house 0 visiting every store.
Level

Medium7 of 10

Topics
Graph, Shortest path, Dynamic programming, Bit manipulation
Solved
No attempts yet

Problem

You have just moved into a new apartment and have a long list of items to buy. Buying this many items means visiting many different stores, and you would like to minimize the amount of driving needed to buy everything on your list.

The city is a set of intersections connected by roads. Your house and every store sit at some intersection. Find the length of the shortest route that starts at your house, visits every store you need to shop at, and returns to your house.

Input

The first line contains a single integer, the number of test cases. Each test case begins with a line containing two integers NN and MM, the number of intersections and the number of roads in the city (1≤N≤1000001 \le N \le 100000, 1≤M≤1000001 \le M \le 100000). The intersections are numbered from 00 to N−1N-1, and your house is at intersection 00. Each of the next MM lines contains three integers XX, YY, and DD, meaning that intersections XX and YY are connected by a bidirectional road of length DD. The next line contains a single integer SS, the number of stores you must visit (1≤S≤101 \le S \le 10). Each of the following SS lines contains one integer, the intersection at which a store is located. Every store is reachable from your house.

Output

For each test case, output a single line containing one integer: the length of the shortest shopping trip that starts at your house, visits all the stores, and returns to your house.

Examples1

  1. Example 1

    Input
    1
    4 6
    0 1 1
    1 2 1
    2 3 1
    3 0 1
    0 2 5
    1 3 5
    3
    1
    2
    3
    
    Expected output
    4