AIRPORTS
A team of engineers is designing the public transportation network of the country. Suppose there are cities in the country, and initially, there are no railways or airports. The engineers know the cost of constructing airports in of these cities. Also, they know the costs of constructing railway lines, each of which can connect a pair of cities without passing through any other city.
The goal of the engineers is to connect all cities with each other. Two cities are considered connected if they are connected by a railway (possibly through intermediate cities) or if each of them is connected by railway to another city that has an airport.
Write a program to calculate the minimum cost to connect all cities.
Input
The first line of input contains three natural numbers , , and : the number of cities, the number of possible airports, and the number of possible railway lines.
Each of the next lines of input will contain two natural numbers and , separated by a space, indicating the cost of constructing an airport in the -th city. Assume that the cities are numbered from to , and that for each city, at most one airport cost is provided.
Each of the next lines of input will contain three natural numbers , , and , separated in pairs by a space, indicating the cost of constructing a railway line connecting the -th and -th cities. Assume that the railway lines operate in both directions, that the numbers and are different, and that for a pair of cities, at most one railway line cost is provided. Also, assume that if all railway lines are constructed, then every city will be connected to every other city.
Output
The output should consist of a single line containing a single natural number: the minimum cost to connect all cities.
Constraints
Execution time limit: 1 sec.
Memory limit: 64 MB.
Example of Input - Output:
STDIN (airports.in)
7 2 8
1 5
7 3
1 2 3
1 3 2
6 4 2
3 5 2
5 2 1
5 6 9
6 7 2
2 3 5
STDOUT (airports.out)
17
Explanation of the Example: The minimum cost arises if airports are constructed in cities and , with a cost of , and railway lines between cities , , , , and with a cost of , resulting in a total cost of .
Comments