This page is still under construction.

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

Two-Step Shortest Path 3

Time limit6sMemory limit1024 MB

Summary
Find the shortest path from X to Z in a weighted undirected graph that visits at least three of the P given intermediate vertices.
Level

Hard8 of 10

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

Problem

Seojun was very happy to receive a world map from his father as a birthday present. He wants to develop a program that finds the shortest path on the world map and give it to his father as a token of thanks. The world map is an undirected graph whose vertices are cities and whose edges are roads between cities, and the length of a road is the weight of the edge. Help our Seojun by finding the shortest distance from the start vertex X to the destination vertex Z while passing through at least three of the P intermediate vertices.

Input

The first line gives the number of vertices N (10 ≤ N ≤ 100,000) and the number of edges M (10 ≤ M ≤ 300,000).

The next M lines give edge information u v w, describing a bidirectional road with integer weight w between city u and city v. (1 ≤ u, v ≤ N, u ≠ v, 1 ≤ w ≤ 1,000,000)

The next line gives X Z. (1 ≤ X, Z ≤ N, X ≠ Z)

The next line gives P. (3 ≤ P ≤ min(100, N - 3))

The next line gives P distinct intermediate vertices Y (1 ≤ Y ≤ N, X ≠ Y ≠ Z), separated by spaces.

Output

Print the shortest distance from the start vertex X to the destination vertex Z while passing through at least three of the P intermediate vertices. If the destination vertex Z cannot be reached, print -1.

Examples1

  1. Example 1

    Input
    12 19
    1 2 1
    1 3 1
    1 4 10
    1 5 10
    2 3 1
    2 6 10
    3 4 1
    3 7 1
    4 5 10
    4 8 10
    5 9 1
    6 7 1
    6 10 1
    7 8 1
    7 10 10
    8 11 10
    9 11 1
    10 12 1
    11 12 1
    1 12
    4
    2 4 5 7
    
    Expected output
    8