#P3639. [APIO2013] 道路费用

    ID: 1429 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2013APIO生成树连通块强连通分量,缩点

[APIO2013] 道路费用

Description

The Kingdom of Happiness can be described as a set of NN towns (numbered 11 to NN), initially connected by MM bidirectional roads (numbered 11 to MM). Town 11 is the central town. It is guaranteed that starting from town 11, one can reach any other town using these roads. All roads are toll roads: for road ii, a user must pay cic_i cents to the road’s owner. It is known that all cic_i are pairwise distinct. Recently, KK new roads were built, all owned by Mr. Greedy\text{Mr. Greedy}. Mr. Greedy\text{Mr. Greedy} can decide the toll for each new road (these tolls may be equal), and he must announce these tolls tomorrow.

Two weeks later, the Kingdom of Happiness will host a grand carnival. A large number of participants will travel along the roads to the central town. In total, pjp_j participants will start from town jj and head to town 11. These people will travel only along a selected set of roads, and this selected set of roads will be announced the day before the event. According to an ancient custom, this set is chosen by the richest person in the kingdom, namely Mr. Greedy\text{Mr. Greedy}. By the same custom, the chosen set must minimize the sum of tolls of all selected roads and still ensure that everyone can travel from town jj to town 11 (therefore, the selected roads form a “minimum spanning tree” with respect to the tolls as edge weights). If there are multiple such sets, Mr. Greedy\text{Mr. Greedy} may choose any of them, as long as the total toll is minimal.

Mr. Greedy\text{Mr. Greedy} understands clearly that his revenue from the KK new roads depends not only on the toll values. The revenue of a road equals the total amount paid by all people who pass through it. More precisely, if pp people pass through road ii, the revenue of road ii is the product ci×pc_i \times p. Note that Mr. Greedy\text{Mr. Greedy} can only collect tolls from the new roads, since the original roads are not his.

Mr. Greedy\text{Mr. Greedy} has a scheme. He plans to maximize his revenue by manipulating the tolls and the choice of roads. He wants to set the toll for each new road (to be announced tomorrow) and choose the roads used for the carnival (to be announced the day before the carnival) so that his total revenue from the KK new roads is maximized. Note that Mr. Greedy\text{Mr. Greedy} must still follow the custom of selecting a road set with the minimum total toll.

You are a journalist and you want to expose his plan. To do this, you must first write a program to determine how much revenue Mr. Greedy\text{Mr. Greedy} can obtain through his scheme.

Input Format

Your program must read from standard input. The first line contains three space-separated integers N,M,KN, M, K. The next MM lines describe the initial MM roads. In these MM lines, the ii-th line contains space-separated integers ai,bi,cia_i, b_i, c_i, indicating a bidirectional road between aia_i and bib_i with toll cic_i. The next KK lines describe the KK newly built roads. In these KK lines, the ii-th line contains space-separated integers xix_i and yiy_i, indicating a new road connecting towns xix_i and yiy_i. The last line contains NN space-separated integers, where the jj-th is pjp_j, the number of people traveling from town jj to town 11.

Constraints: $1 \leq N \leq 10^5, 1 \leq K \leq 20, 1 \leq M \leq 3 \times 10^5$. For each ii and jj, 1ci,pj1061 \leq c_i, p_j \leq 10^6, and if iii \neq i', then cicic_i \neq c_{i'}. Between any two towns, there is at most one road (including newly built roads).

Output Format

Your program must output exactly one integer to standard output, which is the maximum obtainable revenue.

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
400

Hint

In the sample, Mr. Greedy\text{Mr. Greedy} should set the toll of the new road (1,3)(1,3) to 55 cents. With this toll, he can choose roads (3,5),(1,2),(2,4),(1,3)(3,5), (1,2), (2,4), (1,3) to minimize the total toll, which is 1414. The 3030 people from town 33 and the 5050 people from town 55 will pass through the new road on their way to town 11, so he can obtain the best revenue of (30+50)×5=400(30+50)×5=400 cents.

If instead we set the toll of the new road (1,3)(1,3) to 1010 cents, then by the customary constraint Mr. Greedy\text{Mr. Greedy} must choose (3,5),(1,2),(2,4),(2,3)(3,5), (1,2), (2,4), (2,3), because this is the unique set with minimum total toll. Therefore, during the carnival the road (1,3)(1,3) will bring no revenue.

We will use the following 55 types of test cases to evaluate your program.

  1. (International 1616 points, Domestic 1515 points) N10,M20,K=1N \leq 10, M \leq 20, K = 1.
  2. (International 1818 points, Domestic 2020 points) N30,M50,K10N \leq 30, M \leq 50, K \leq 10.
  3. (International 2222 points, Domestic 2020 points) N103,M5×103,K10N \leq 10^3, M \leq 5 \times 10^3, K \leq 10.
  4. (International 2222 points, Domestic 2020 points) N105,M3×105,K15N \leq 10^5, M \leq 3 \times 10^5, K \leq 15.
  5. (International 2222 points, Domestic 2525 points) N105,M3×105,K20N \leq 10^5, M \leq 3 \times 10^5, K \leq 20.

update: 2024/07/04 Two test points were removed, and the tests were changed to bundled.

Translated by ChatGPT 5