#P6815. [PA 2009] Cakes
[PA 2009] Cakes
Description
Pastry chefs from all over the country have come to the cake convention. At the convention, there is a contest where cakes are baked by teams of pastry chefs. Each team (three pastry chefs) can bake at most one cake, and a pastry chef may belong to multiple teams. Unfortunately, some pastry chefs do not accept each other and will not cooperate with each other.
We know how much flour each pastry chef needs to bake a cake. For a team of three, the flour required is the maximum flour requirement among its members. The contest must ensure that every possible team of three pastry chefs that can cooperate is able to bake one cake. Your task is to compute the total amount of flour used during the contest.
Input Format
The first line contains two integers and (, ), denoting the number of pastry chefs and the number of pairs of pastry chefs who accept each other.
The second line contains integers (), where is the flour requirement of the -th pastry chef.
The next lines each contain two distinct integers (, ), meaning that pastry chef and pastry chef accept each other. No accepting pair appears more than once.
Output Format
Print one integer on one line, the total amount of flour used during the entire contest.
5 7
1 5 3 4 2
1 2
2 3
5 2
4 3
3 1
1 4
5 1
14
Hint
Sample Explanation
The following teams exist: , , . They require , , and units of flour respectively, so the total is .
Translated by ChatGPT 5
京公网安备 11011102002149号