![]() Image 1. A scheme of farms and roads in the area. Small circles represent farms, lines represent roads. Hub farms are drawn in black, numbers at the roads represent their length. Roads with pipes are highlighted in blue. The choice of roads with pipes is optimal, the total length of pipes is 42. There are 4 undecided farms, with background highlighted in light blue. The scheme illustrates Example 1 below. |
You are given a list of lengths of all roads in the area. Also, you are given a list of all hub farms in the area. Find the minimum total length of all pipes in the project and the number of undecided farms.
The first line of input contains two integers F and R, number of farms and the number of roads.
Farms are labeled by integers 0, 1, ..., F−1.
Next, there are R lines, each specifies one road.
There are three integers on a line specifying a road, the first two are the labels of farms connected by the road
and the third one is the length of the road.
Next, there is a line with single integer H, the number of hub farms.
The next line contains H integers, the list of labels of all hub farms.
It holds, 2 ≤ F ≤ 104, 1 ≤ R ≤ 106, 1 ≤ H ≤ F. All road lengths are positive integers less than 1000.
All adjacent input values on any line are separated by a space.
Ouput consists of one text line with two integers separated by space, representing the minimum pipes network length and the number of undecided farms.
Example 1Input20 31 0 1 4 0 5 2 1 2 9 1 6 5 2 3 6 2 7 2 3 4 2 3 8 7 4 9 5 5 6 7 5 10 1 6 7 8 6 11 3 7 8 9 7 12 5 8 9 3 8 13 8 9 14 2 10 11 4 10 15 6 11 12 3 11 16 5 12 13 4 12 17 4 13 14 3 13 18 2 14 19 5 15 16 2 16 17 6 17 18 8 18 19 2 4 3 8 15 17Output 42 4 |
![]() Image 2. A scheme of farms, roads and optimal choice of roads with pipes in Example 1. Features of the scheme are explained in the description of Image 1. |
Example 2Input13 16 0 1 1 0 5 1 0 3 1 1 2 1 2 7 1 2 4 1 3 6 1 4 6 1 5 10 1 6 8 1 6 9 1 7 12 1 8 10 1 9 12 1 10 11 1 11 12 1 4 0 2 12 10Output 4 5 |
![]() Image 3. A scheme of farms, roads and optimal choice of roads with pipes in Example 2. Features of the scheme are explained in the description of Image 1. |
Example 3Input8 11 0 1 4 1 2 4 2 3 2 3 4 7 4 7 7 7 6 2 6 5 4 5 0 4 1 5 1 2 6 1 3 7 1 2 0 4Output 18 0 |
![]() Image 4. A scheme of farms, roads and optimal choice of roads with pipes in Example 3. Note there are no undecided farms in Example 3. Features of the scheme are explained in the description of Image 1. |
The public data set is intended for easier debugging and approximate program correctness checking. The public data set is stored also in the upload system and each time a student submits a solution it is run on the public dataset and the program output to stdout and stderr is available to him/her.
Link to public data set