Jonathan Sumabat 2

View as PDF

Submit solution

Points: 12
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Jonathan Sumabat is visiting Japan! During his visit, he decides to explore the moe culture of Akihabara. He explores a series of maid cafes and due to his stunning and charming looks some of the maids give him their phone numbers. When Jonathan Sumabat goes back home he tries to text every single one of the maids, however he finds that he has lost some of the phone numbers at the cafe! Jonathan Sumabat is exhausted and has asked for your help to determine the shortest route he can take to each cafe he needs to retrieve phone numbers from.

Jonathan Sumabat is the best cat girl maid!

Input Specification

The first line is an integer n (1 \le n \le 100) representing the number of maid cafes Jonathan Sumabat visited in total.
These cafes are numbered 1 to n.
The next line is an integer m (1 \le m \le 2n) representing the number of roads in Akihabara that Jonathan Sumabat can take.
The next m lines contain three space separated integers:

  • The first two integers represent a road connecting two valid maid cafes or Jonathan Sumabat's starting point, represented with 0.
    He can use this road both ways, starting from the first cafe to the second or vice versa.
  • The third integer is the length l (1 \le l \le 100) of the road in meters.

The next integer is p (1 \le p \le 10) representing the number of phone numbers Jonathan Sumabat needs to recover.
The next p lines contain p_i (1 \le p_i \le n), the maid cafe each number was lost at.
There will be at most 1 number lost at any given maid cafe. It is guaranteed that a path that encounters all cafes needed exists.

Output Specification

Output the length of the shortest route that Jonathan Sumabat can take in order to pass by every maid cafe he needs to recover a phone number from.

Sample Input

5
8
0 1 11
0 2 6
2 1 3
1 3 2
2 3 4
2 4 9
3 4 7
4 5 7
3
1
4
3

Sample Output

18

Explanation for Sample

The city of Akihabara is visualized in the following picture, with circles representing the maid cafes and the lines connecting them representing the roads. The red circles represent maid cafes that a number must be retrieved from. The green lines represent the shortest path that can be taken to encounter all needed maid cafes.

Graph


Comments


  • -5
    coconut  commented on Dec. 12, 2019, 8:40 p.m.

    This comment is hidden due to too much negative feedback. Click here to view it.