#P5578. [PA 2014] Fiolki
[PA 2014] Fiolki
Description
The chemist Gili wants to make a magical potion to save the world.
Gili has different liquid substances and bottles (both numbered from to ). Initially, bottle contains grams of substance .
Gili needs to perform several steps to make the potion. In step , she pours all the liquid from bottle into bottle . After that, bottle will no longer be used. You may assume the bottles have unlimited capacity.
Gili knows that some pairs of substances will react together and produce precipitate. The reaction is: gram of substance and gram of substance produce grams of precipitate, and the reaction continues until one reactant is exhausted. The precipitate produced will not react with any substance.
When there is more than one pair of substances that can react in the same bottle, Gili knows the order in which they react. After each pouring, Gili waits until all reactions finish before performing the next step.
Gili wants to know the total amount of precipitate produced during the whole process.
Input Format
The first line contains three integers , representing the number of bottles (i.e. the number of substances), the number of steps, and the number of possible reactions.
The second line contains integers , representing the initial mass of the substance in each bottle.
The next lines each contain two integers , representing step . It is guaranteed that will not appear in any later step.
The next lines each contain a pair of substances that can react, given in the priority order of reactions. The same reaction will not appear more than once.
Output Format
Output the total mass of precipitate produced.
3 2 1
2 3 4
1 2
3 2
2 3
6
Hint
For of the testdata, , , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号