The university is currently transferring its research software from the old campus to the new campus.
Each server in the new campus falls into one the two categories - fast or slow.
There is a specific signal delay between any two directly connected servers in the new campus.
Total delay in a part of the network is equal to the sum of delays between all pairs of
directly connected servers in that part.
The biological experiments managing software (BEMS) was tailored to the network topology of the servers
in the old campus. When BEMS is transferred to the new network, it will use only part of the new network,
and the topology of that part must be identical to the topology of the original network.
From the point of view of BEMS, for each server X in the old network there will be exactly one server in the new network,
denoted as a X counterpart.
The set of counterparts of all servers in the old network, together with all direct
connections between these counterpart servers, is denoted as counterpart network.
To help the administrators to select the servers in the counterpart network, the following rules were specified.
Figure 1. Two example schemes of old and new campus networks with the fast servers highlighted in black and with the connections of the optimal counterpart network highlighted in orange color. In example a), the optimal counterpart network contains 4 out of 5 fast servers and the total delay in it is equal to 55. In example b), the optimal counterpart network contains 4 out of 7 fast servers and the total delay in it is equal to 35. Note that, for example, the optimal counterpart network cannot contain servers 11 and 12 instead of servers 1 and 2. The number of fast servers would be the same, the total delay would be only 31. However, such counterpart network would violate rule 3, because directly connected servers 12 and 13 would be the counterparts of servers 5 and 6 in the old network, and those are not directly connected. The schemes a) and b) illustrate Example 1 and 2 below. |
You are given the topology of both campus networks, old and new, the list of fast servers and the delays between directly connected servers. Find the number of fast servers and the total delay in an optimal counterpart network of the old campus network.
The first input line contains two positive integers N1, M1, the number of servers
and the number of direct connections between pairs of servers in the old campus network.
The servers are labeled by integers 0, 1, ..., N1−1.
Next M1 lines describe direct connections in the old campus network.
Each line specifies one direct connection by the labels, separated by space, of its end servers.
Next, there is a line with two positive integers N2, M2, F2, the number of servers,
the number of direct connections between pairs of servers, and the number of fast servers in the new campus network.
The servers are labeled by integers 0, 1, ..., N2−1.
The next line contains the list of labels of the fast servers, it is presented as
F2 integers separated by spaces.
Next M2 lines describe direct connections in the new campus network.
Each line specifies one direct connection by three integers separated by spaces. The first two
integers are the labels of the end servers of the connection, the third integer is the signal time delay
along the direct connection between these two servers.
It holds, 2 ≤ N1 ≤ 10, 2 ≤ M1 ≤ 40,
5 ≤ N2 ≤ 30, 5 ≤ M2 ≤ 350,
1 ≤ F2 ≤ N2.
The output contains one text line with two integers separated by space, the number of fast servers and the total delay in an optimal counterpart network.
Example 1Input5 5 0 2 0 3 1 2 2 3 3 4 10 18 5 2 4 6 8 9 0 1 1 1 2 1 2 3 2 3 4 3 4 5 4 5 6 5 6 7 6 7 8 7 8 0 8 1 8 9 2 4 10 5 7 11 9 1 12 9 2 13 9 4 14 9 5 15 9 7 16 9 8 17Output 4 55The data of Example 1 is depicted in Figure 1 a). |
Example 2Input8 9 0 1 1 2 2 3 4 5 6 7 0 4 1 5 2 6 3 7 15 22 7 1 3 5 7 9 11 13 0 1 5 1 2 3 2 3 7 3 4 2 5 6 8 6 7 5 7 8 2 8 9 4 10 11 5 11 12 1 12 13 6 13 14 3 0 5 4 5 10 2 1 6 9 6 11 2 2 7 1 7 12 6 3 8 8 8 13 4 4 9 7 9 14 4Output 4 35The data of Example 2 is depicted in Figure 1 b). |
Example 3Input10 9 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 15 22 7 1 3 5 7 9 11 13 0 1 5 1 2 3 2 3 7 3 4 2 5 6 8 6 7 5 7 8 2 8 9 4 10 11 5 11 12 1 12 13 6 13 14 3 0 5 4 5 10 2 1 6 9 6 11 2 2 7 1 7 12 6 3 8 8 8 13 4 4 9 7 9 14 4Output 5 29 |
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 the public data set