#P8385. [POI 2003] Smugglers
[POI 2003] Smugglers
Problem Description
Byteotia is famous around the world for its rich gold resources. Therefore, every year there are a lot of gold trades on the border with its neighboring country Bitland. Unfortunately, because taxes are very heavy, merchants must pay of the mineral’s price as customs duty when carrying minerals across the border. Luckily, some alchemists have invented methods to convert one kind of metal mineral into another. In this way, during trading, one can first convert an expensive mineral into a cheaper one, and after crossing the border, convert it back. However, since this work is time-consuming and laborious, the alchemists charge a corresponding fee for each conversion.
Now a merchant wants to carry kg of gold across the border, and he wants to know what the minimum total cost is.
Input Format
The first line contains a single integer , the number of kinds of metal minerals.
The next lines give the unit price of kg for each metal. The number on line is the unit price of the -th metal. We assume that gold has index .
Next comes a positive integer , meaning there are conversion methods.
The next lines each describe one conversion with three numbers , , , meaning converting kg of metal into kg of metal costs . For any specific pair of metals and , it appears at most once.
Output Format
Output one line: the minimum total cost to carry kg of gold across the border.
4
200
100
40
2
6
1 2 10
1 3 5
2 1 25
3 2 10
3 4 5
4 1 50
60
Hint
Constraints: for of the testdata, , , , , .
Translated by ChatGPT 5