#P4695. [PA 2017] Banany
[PA 2017] Banany
Description
Bajtazar is a merchant. Every day, he leaves the city he is currently in and travels to another city to sell bananas. Each road has a toll fee, and the destination city provides some revenue (note that intermediate cities provide no revenue). Each day, the fee of one road changes, or the revenue of one city changes. Bajtazar wants to know, after he wakes up each day, which city he should choose as the destination to obtain the maximum profit, and on the next day he will depart from that city again.
There are cities, connected by roads, and every city is reachable from every other city. City has revenue , and each edge has a fee .
If he does business from to , the profit is
There are days in total.
Initially, Bajtazar is in city . Each day, after the changes take place, he will go to the next city. He will choose the one that yields the maximum profit; if there are multiple, he chooses the one with the smallest index. However, he cannot stay in the same city and must leave.
Input Format
The first line contains two integers and .
The second line contains integers representing the revenues .
The next lines each contain , describing an edge and its fee.
The next lines are of two types.
- Input means replacing the revenue of city with the new value.
- Input means replacing the fee of the edge connecting cities with the new value.
Output Format
For each change, output one line. In total, output answers, each indicating Bajtazar's next destination after the change.
4 4
10 20 30 50
1 2 5
2 3 7
2 4 57
1 3 28
1 1 25
2 3 2 1
2 2 4 13
3 1 3 4
Hint
Constraints: , , .
Translated by ChatGPT 5
京公网安备 11011102002149号