#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 33 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 nn and mm (1n1051 \le n \le 10^5, 1m2.5×1051 \le m \le 2.5\times 10^5), denoting the number of pastry chefs and the number of pairs of pastry chefs who accept each other.

The second line contains nn integers p1,p2,,pnp_1, p_2, \dots, p_n (1pi1061 \le p_i \le 10^6), where pip_i is the flour requirement of the ii-th pastry chef.

The next mm lines each contain two distinct integers ai,bia_i, b_i (1ai,bin1 \le a_i, b_i \le n, aibia_i \ne b_i), meaning that pastry chef aia_i and pastry chef bib_i 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: (1,2,3)(1,2,3), (1,2,5)(1,2,5), (1,3,4)(1,3,4). They require 55, 55, and 44 units of flour respectively, so the total is 5+5+4=145+5+4=14.

Translated by ChatGPT 5