#P3280. [SCOI2013] 摩托车交易
[SCOI2013] 摩托车交易
Description
After being discharged from the hospital, mzry1992 bought a new motorcycle and started a gold delivery business among nearby cities. In the place where mzry1992 lives, cities are connected by bidirectional highways. In addition, each highway has a load limit: ignoring the weight of the rider and the motorcycle, if the amount of cargo carried exceeds a certain value, that highway cannot be used.
This year, mzry1992 received orders from different cities. Each order either requests to buy up to a certain amount of gold from him, or to sell up to a certain amount of gold to him. Since orders do not arrive simultaneously, to maintain his reputation, mzry1992 must trade with customers in the order the orders arrive. When trading with the -th customer, he performs the following steps:
- Travel to the city of the -th customer. Passing through other cities en route is fully allowed.
- Trade with the -th customer. In this process, he wants to maximize the transaction amount subject to the following two constraints: (a) After finishing the transaction with the last customer, he must hold no gold. (b) Because gold is valuable, he is not allowed to overbuy in a way that would force him to discard gold later during transportation.
Initially, mzry1992 is located in the city of the first order. Here is some good news: someone has given mzry1992 a free trial to use the railway system among nearby cities. Specifically, if he wants to travel from city to city , and both and have railway stations, then he can carry both gold and his motorcycle by train from to , assuming there is no load limit on the train.
Given the transportation network and the orders, please help mzry1992 compute, for each customer who buys gold from him (i.e., his sell transactions), the quantity they purchase.
Input Format
The first line contains three integers , denoting the number of cities, the number of highways, and the number of cities with railway stations, respectively.
The second line contains distinct integers, each between and , representing a permutation of the cities: the order in which the orders arrive.
The third line contains integers, where the -th number is the upper limit of the order in city . If , then from the perspective of mzry1992 it is a buy order (he buys gold) with upper limit . If , then it is a sell order (he sells gold) with upper limit .
Each of the next lines contains three integers , meaning there is a bidirectional highway between cities and with load limit . City indices are from to .
The last line contains integers, which are the indices of the cities that have railway stations.
Output Format
In the order of the orders, for each sell transaction, output one line containing a single integer , the amount of gold sold.
3 3 2
2 3 1
-6 5 -3
1 3 5
2 3 2
2 1 6
1 3
3
2
4 4 0
1 2 3 4
5 4 -6 -1
1 2 4
2 3 100
3 4 1
4 1 4
6
1
Hint
Sample explanation:
- First sample: One valid plan is to initially buy units of gold in city , take the third highway to city , then take the train to city , sell units of gold in city , take the train back to city , and sell units of gold in city .
- Second sample: One valid plan is to initially buy units of gold in city , take the first highway, buy units of gold in city , take the second highway, sell units of gold in city , take the third highway, and sell unit of gold in city .
Constraints:
- For of the testdata, , .
- For of the testdata, , .
- For of the testdata, , , , , . It is guaranteed that any two cities are connected via highways.
Translated by ChatGPT 5
京公网安备 11011102002149号