#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 nn orders from nn 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 ii-th customer, he performs the following steps:

  1. Travel to the city of the ii-th customer. Passing through other cities en route is fully allowed.
  2. Trade with the ii-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 AA to city BB, and both AA and BB have railway stations, then he can carry both gold and his motorcycle by train from AA to BB, 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 n,m,qn, m, q, denoting the number of cities, the number of highways, and the number of cities with railway stations, respectively.

The second line contains nn distinct integers, each between 11 and nn, representing a permutation of the cities: the order in which the orders arrive.

The third line contains nn integers, where the ii-th number is the upper limit bib_i of the order in city ii. If bi>0b_i > 0, then from the perspective of mzry1992 it is a buy order (he buys gold) with upper limit bib_i. If bi<0b_i < 0, then it is a sell order (he sells gold) with upper limit bi-b_i.

Each of the next mm lines contains three integers u,v,wu, v, w, meaning there is a bidirectional highway between cities uu and vv with load limit ww. City indices are from 11 to nn.

The last line contains qq 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 xx, 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 55 units of gold in city 22, take the third highway to city 11, then take the train to city 33, sell 33 units of gold in city 33, take the train back to city 11, and sell 22 units of gold in city 11.
  • Second sample: One valid plan is to initially buy 44 units of gold in city 11, take the first highway, buy 33 units of gold in city 22, take the second highway, sell 66 units of gold in city 33, take the third highway, and sell 11 unit of gold in city 44.

Constraints:

  • For 20%20\% of the testdata, n100n \le 100, m200m \le 200.
  • For 50%50\% of the testdata, n3000n \le 3000, m6000m \le 6000.
  • For 100%100\% of the testdata, 1n1051 \le n \le 10^5, n1m2×105n - 1 \le m \le 2\times 10^5, 0qn0 \le q \le n, 0<bi<1090 < |b_i| < 10^9, 0<w<1090 < w < 10^9. It is guaranteed that any two cities are connected via highways.

Translated by ChatGPT 5