Cheap Deliveries

Given a weighted undirected graph and k up to 18 delivery pairs, find the order of deliveries that minimizes total travel distance, or report -1 if some delivery is unreachable.

Medium7GraphShortest pathDynamic programmingBit manipulationNo attempts yetTime limit2sMemory limit512 MB

Problem

Abu runs a delivery service that carries items from one city to another. One day Abu receives kk items to deliver. Each item must be carried from its start city to its destination city, and only one item can be carried at a time. The delivery order is free, as long as every item is delivered. Abu starts in the start city of some item, delivers it to its destination city, then moves to the start city of the next item and continues until no item remains.

Every road is bidirectional, and two cities may be connected by more than one road. Abu may use any road as many times as needed.

Given the list of cities, the roads between them with their lengths, and the list of deliveries, determine the minimum total travel distance needed to finish all deliveries in the most efficient order.

Input

The first line contains three integers nn, mm and kk: the number of cities, the number of roads and the number of items (2n,m1042 \le n, m \le 10^4, 1k181 \le k \le 18).

Each of the next mm lines contains three integers uiu_i, viv_i and lil_i (1ui,vi1041 \le u_i, v_i \le 10^4, 1li1061 \le l_i \le 10^6), meaning there is a road of length lil_i between city uiu_i and city viv_i.

Each of the next kk lines contains two integers fif_i and did_i (1fi,di1041 \le f_i, d_i \le 10^4), meaning item ii must be delivered from city fif_i to city did_i.

Output

Print a single integer: the minimum total travel distance when all items are delivered in the optimal order, or 1-1 if it is impossible to deliver all items.

Hint

In the first case, starting from city 55 and delivering the third item to city 33, then moving to city 11 and delivering the second and first items in order, gives a total travel distance of 1212, which is optimal.

In the second case, cities 11, 22 and 44 are disconnected from cities 33 and 55, so it is impossible to deliver all items.