#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 50%50\% 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 11 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 nn, the number of kinds of metal minerals.

The next nn lines give the unit price of 11 kg for each metal. The number pkp_k on line k+1k+1 is the unit price of the kk-th metal. We assume that gold has index 11.

Next comes a positive integer mm, meaning there are mm conversion methods.

The next mm lines each describe one conversion with three numbers aa, bb, cc, meaning converting 11 kg of metal aa into 11 kg of metal bb costs cc. For any specific pair of metals aa and bb, it appears at most once.

Output Format

Output one line: the minimum total cost to carry 11 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 100%100\% of the testdata, 1n50001 \le n \le 5000, 0pk1090 \le p_k \le 10^9, 0m1000000 \le m \le 100000, 1a,bn1 \le a,b \le n, 0c100000 \le c \leq 10000.

Translated by ChatGPT 5