#P3639. [APIO2013] 道路费用
[APIO2013] 道路费用
Description
The Kingdom of Happiness can be described as a set of towns (numbered to ), initially connected by bidirectional roads (numbered to ). Town is the central town. It is guaranteed that starting from town , one can reach any other town using these roads. All roads are toll roads: for road , a user must pay cents to the road’s owner. It is known that all are pairwise distinct. Recently, new roads were built, all owned by . 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, participants will start from town and head to town . 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 . 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 to town (therefore, the selected roads form a “minimum spanning tree” with respect to the tolls as edge weights). If there are multiple such sets, may choose any of them, as long as the total toll is minimal.
understands clearly that his revenue from the 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 people pass through road , the revenue of road is the product . Note that can only collect tolls from the new roads, since the original roads are not his.
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 new roads is maximized. Note that 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 can obtain through his scheme.
Input Format
Your program must read from standard input. The first line contains three space-separated integers . The next lines describe the initial roads. In these lines, the -th line contains space-separated integers , indicating a bidirectional road between and with toll . The next lines describe the newly built roads. In these lines, the -th line contains space-separated integers and , indicating a new road connecting towns and . The last line contains space-separated integers, where the -th is , the number of people traveling from town to town .
Constraints: $1 \leq N \leq 10^5, 1 \leq K \leq 20, 1 \leq M \leq 3 \times 10^5$. For each and , , and if , then . 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, should set the toll of the new road to cents. With this toll, he can choose roads to minimize the total toll, which is . The people from town and the people from town will pass through the new road on their way to town , so he can obtain the best revenue of cents.
If instead we set the toll of the new road to cents, then by the customary constraint must choose , because this is the unique set with minimum total toll. Therefore, during the carnival the road will bring no revenue.
We will use the following types of test cases to evaluate your program.
- (International points, Domestic points) .
- (International points, Domestic points) .
- (International points, Domestic points) .
- (International points, Domestic points) .
- (International points, Domestic points) .
update: 2024/07/04 Two test points were removed, and the tests were changed to bundled.
Translated by ChatGPT 5
京公网安备 11011102002149号