This page is still under construction.

Parts of this page are still being built. What you see may change.

In and Out

Time limit1sMemory limit128 MB

Summary
Find the shortest round trip from node 1 to node N and back, where each sentry node is visited at most once across both legs.
Level

Hard8 of 10

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

Problem

The young pirate Will Twister has lost his precious medallion, once given to him by his father. It is now in the hands of Governor Goose. Because the medallion means so much to Will, he decides to steal it back. His presence will not go unnoticed (he is no ninja), so to improve his chances of a clean getaway he will move under the cover of night. That makes the journey to the governor's house dangerous, though, because walking through town at night is suspicious.

Throughout the town, sentries (stationary guards) are posted at strategically chosen junctions. Will is not a good fighter, so he relies on surprise and speed to slip past them. However, if he were to pass the same sentry on both the outbound and the return journey, the element of surprise would be gone the second time and he would risk being caught. Therefore he never wants to pass the same sentry twice.

Will's journey starts and ends at the harbor, where he arrives and departs by boat. He has a map of the town marked with the sentry locations. Since he will be doing a lot of running, he wants the shortest possible round trip to the governor's house and back that does not take him past any sentry more than once. Can you help him find it?

Input

The first line contains a single integer: the number of test cases. Each test case has the following format:

  • One line with two integers NN and RR (2≤N≤10002 \le N \le 1000, 1≤R≤100001 \le R \le 10000): the number of junctions and the number of roads.
  • RR lines, each with three integers aa, bb and ll (1≤a,b≤N1 \le a, b \le N, 1≤l≤10001 \le l \le 1000), meaning there is a bidirectional road of length ll between junctions aa and bb.
  • One line with one integer SS (0≤S≤min⁡(N−2,100)0 \le S \le \min(N - 2, 100)): the number of sentries.
  • One line with SS distinct integers sis_i (2≤si<N2 \le s_i < N): the junctions that have a sentry.

The junctions are numbered 11 through NN. Will's boat is at junction 11 and the governor's house is at junction NN. A path from the boat to the governor's house is guaranteed to exist.

Output

For each test case, output a single line with one integer: the minimum total distance Will must cover for the whole round trip (out to the governor's house and back). If there is no round trip that passes each sentry at most once, output No safe route (without the quotation marks) on its own line instead.

Examples1

  1. Example 1

    Input
    3
    6 7
    1 2 1
    2 3 1
    3 6 1
    1 4 10
    4 3 10
    2 5 10
    5 6 10
    2
    2 3
    5 5
    1 2 1
    1 3 2
    2 4 1
    3 4 2
    4 5 1
    1
    2
    5 5
    1 2 1
    1 3 2
    2 4 1
    3 4 2
    4 5 1
    1
    4
    
    Expected output
    42
    8
    No safe route