#P1875. 佳佳的魔法药水【数据有误】

佳佳的魔法药水【数据有误】

Description

There are two ways to obtain a potion: you can either configure it yourself according to the magic book, or buy it at the magic shop — every kind of potion is available there, though the price may be high. The magic book contains many notes like this:

Mixing 11 unit of potion A with 11 unit of potion B yields 11 unit of potion C. (As for why 1+1=11 + 1 = 1, well... this is the magic world.) Now, you know which potion you need, you also know the prices of all potions that may be involved and all recipes in the magic book. The questions are:

  1. What is the minimum cost to successfully produce this precious potion?
  2. How many different minimum-cost plans are there (two feasible configuration plans are considered different if any step differs)? Assume you initially have no usable potion.

Input Format

The first line contains an integer NN (1N10001 \le N \le 1000), the total number of potions involved. Potions are numbered from 00 to N1N - 1, and potion No. 00 is the final target potion.

The second line contains NN integers, giving the prices (for 11 unit each) of all potions numbered from 00 to N1N - 1 in order at the magic shop.

From the third line onward, each line contains three integers A, B, C, meaning mixing 11 unit of potion A with 11 unit of potion B yields 11 unit of potion C. Note that if a specific pair of potions can be mixed to form a new potion, the result is unique. In other words, there will not be two lines where A and B are the same but C is different.

The input ends with a blank line.

Output Format

Output two integers separated by a space, representing the minimum cost to obtain potion No. 00 and the number of minimum-cost plans.

It is guaranteed that the number of plans does not exceed 26312^{63} - 1.

7 
10 5 6 3 2 2 3 
1 2 0 
4 5 1 
3 6 2

10 3

Hint

Constraints:

The price of each potion is within [1,2.8×104][1, 2.8\times 10^4].

Sample explanation:

There are 33 optimal plans:

  • Buy potion No. 00 directly.
  • Buy potion No. 44 and potion No. 55 to make potion No. 11, buy potion No. 22 directly, then combine to make potion No. 00.
  • Buy potion No. 44 and potion No. 55 to make potion No. 11, buy potion No. 33 and potion No. 66 to make potion No. 22, then combine to make potion No. 00.

Translated by ChatGPT 5