PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000223. Cậu bé và món đồ chơi (The Child and Toy)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Cậu bé và món đồ chơi (The Child and Toy)

The Child and Toy

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A toy contains nn parts connected by mm ropes. Part ii has energy value viv_i. You must remove all parts one at a time.

Removing part ii costs the sum of energy values of its neighbors that have not yet been removed. If no neighbors remain, the cost is zero. Each rope joins two distinct parts, and there is at most one rope per pair.

Find the minimum total cost over all possible removal orders.

Input

  • The first line contains n,mn,m.
  • The second line contains nn numbers v1,…,vnv_1,\ldots,v_n.
  • The next mm lines each contain x,yx,y, a rope between parts xx and yy.

Output

Print one integer: the minimum total energy needed.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 0≤m≤20000\le m\le 2000; 0≤vi≤1050\le v_i\le 10^5; 1≤x,y≤n, x≠y1\le x,y\le n,\ x\ne y; không có cặp dây trùng.
  • Subtask 2 (30 points): 1≤n≤1001\le n\le 100; 0≤m≤20000\le m\le 2000; 0≤vi≤1050\le v_i\le 10^5; 1≤x,y≤n, x≠y1\le x,y\le n,\ x\ne y; không có cặp dây trùng.
  • Subtask 3 (50 points): 1≤n≤10001\le n\le 1000; 0≤m≤20000\le m\le 2000; 0≤vi≤1050\le v_i\le 10^5; 1≤x,y≤n, x≠y1\le x,y\le n,\ x\ne y; không có cặp dây trùng.

Examples

Input

4 3
10 20 30 40
1 4
1 2
2 3

Output

40

Explanation

Remove parts in order 3,2,4,13,2,4,1, paying 20,10,10,020,10,10,0 respectively, totaling 4040. Equivalently, the three ropes must cost at least 1010, 1010, and 2020, giving the lower bound 4040.