PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000114. Giảm chi phí giao hàng (Reducing Delivery Cost)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Giảm chi phí giao hàng (Reducing Delivery Cost)

Reducing Delivery Cost

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A connected weighted undirected graph has nn districts and mm roads with positive costs. There are kk delivery requests (ai,bi)(a_i,b_i), independently choosing a minimum-cost route; requests may repeat or have ai=bia_i=b_i. You may reduce the cost of at most one existing road to zero in both directions. Minimize the sum of shortest travel costs over all requests.

Input

First line: n,m,kn,m,k; then mm lines u,v,wu,v,w; then kk requests a,ba,b. Vertices are 11-indexed.

Output

Print the minimum total cost.

Subtasks

  • Subtask 1 (40 points): 2≤n≤82\le n\le 8, n−1≤m≤16n-1\le m\le 16, 1≤k≤61\le k\le 6, 1≤w≤201\le w\le 20. All input conditions remain in force.

  • Subtask 2 (60 points): 2≤n≤10002\le n\le 1000, n−1≤m≤min⁡(1000,n(n−1)/2)n-1\le m\le\min(1000,n(n-1)/2), 1≤k≤10001\le k\le 1000, 1≤w≤10001\le w\le 1000. All input conditions remain in force.

Examples

Input

6 5 2
1 2 5
2 3 7
2 4 4
4 5 2
4 6 8
1 6
5 3

Output

22

Explanation

Making either road (2,4) or (4,6) free reduces the total shortest delivery cost to 22.