This page is still under construction.

Parts of this page are still being built. What you see may change.

Toll

Time limit3sMemory limit128 MB

Summary
A billionaire sets tolls on K new roads of his choosing so that the minimum spanning tree routing all traffic to town 1 maximizes his revenue, where K is at most 20.
Level

Hard8 of 10

Topics
Minimum spanning tree, Greedy, Tree, Dynamic programming
Solved
No attempts yet

Problem

Happyland is a country of NN towns numbered 11 to NN. Town 11 is the capital. Initially the towns are connected by MM two-way roads numbered 11 to MM, and it is guaranteed that every town can reach town 11 using these roads. Every road is a toll road: using road ii costs cic_i cents, paid to that road's owner. All cic_i are distinct.

Recently a billionaire, Mr. Greedy, finished building KK additional new roads, all of which he owns. He may set the toll of each new road to any positive integer he likes (the new tolls need not be distinct), and he must announce these tolls tomorrow.

Two weeks from now a huge carnival will take place. For each town jj, exactly pjp_j people will start at town jj and travel to the capital, town 11. They may only use a set of selected roads, which is announced the day before the carnival. By tradition, the selected roads are chosen by the richest person in Happyland, Mr. Greedy. The same tradition requires the selected set to (a) still let everyone travel from every town to town 11, and (b) have the minimum possible total toll among all such sets. In other words, the selected roads must form a minimum spanning tree, using the tolls as edge weights. When several sets tie for the minimum total, Mr. Greedy may pick any one of them.

Mr. Greedy earns money only from the new roads (he owns none of the old ones). The revenue from a road equals its toll multiplied by the number of people who walk along it: if road ii has toll cic_i and pp people use it, its revenue is ci⋅pc_i \cdot p.

Mr. Greedy wants to maximize his total revenue from the KK new roads by cleverly choosing the new tolls and, when the minimum-total set is not unique, by cleverly choosing the selected roads, while still obeying the tradition of minimum total toll. Determine the maximum total revenue he can obtain.

Input

The first line contains three integers NN, MM, and KK.

Each of the next MM lines contains three integers aia_i, bib_i, and cic_i: old road ii connects towns aia_i and bib_i and has toll cic_i.

Each of the next KK lines contains two integers xix_i and yiy_i: new road ii connects towns xix_i and yiy_i.

The last line contains NN integers p1,p2,…,pNp_1, p_2, \dots, p_N, where pjp_j is the number of people starting from town jj.

Constraints:

  • 1≤N≤1000001 \le N \le 100000
  • 1≤K≤201 \le K \le 20
  • 1≤M≤3000001 \le M \le 300000
  • 1≤ci,pj≤1061 \le c_i, p_j \le 10^6
  • All cic_i are distinct.
  • Between any two towns there is at most one road (counting both old and new roads).
  • Using only the old roads, every town can reach town 11.

Output

Print a single integer: the maximum total revenue Mr. Greedy can obtain.

Hint

In the situation shown above, Mr. Greedy should set the toll of the new road (1,3)(1,3) to 55. With this toll he can select the roads (3,5)(3,5), (1,2)(1,2), (2,4)(2,4), and (1,3)(1,3), whose total toll is the minimum possible, 1414. The 3030 people from town 33 and the 5050 people from town 55 then cross the new road on their way to town 11, so its revenue is (30+50)×5=400(30 + 50) \times 5 = 400.

If instead he set the toll of (1,3)(1,3) to 1010, the tradition would force him to select (3,5)(3,5), (1,2)(1,2), (2,4)(2,4), and (2,3)(2,3), the only minimum-total set, and no one would use the new road, earning him nothing.

Examples3

  1. Example 1

    Input
    5 5 1
    3 5 2
    1 2 3
    2 3 5
    2 4 4
    4 3 6
    1 3
    10 20 30 40 50
    
    Expected output
    400
    
  2. Example 2

    Input
    3 2 1
    1 2 1
    2 3 2
    1 3
    5 7 9
    
    Expected output
    18
    
  3. Example 3

    Input
    5 4 1
    1 2 5
    1 3 6
    1 4 7
    1 5 8
    2 3
    3 4 5 6 7
    
    Expected output
    30