404041: GYM101401 E Roads (B)

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Roads (B)time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

Some cities are now occupied. Mr. Light wants to cut all paths that go between specific pairs of cities. Destroying any road on a path cuts that path. The cost of destroying each road di is given.

Mr. Light already destroyed some (one or more) roads, and the cost for the destroyed roads is given as zero. Find the minimum total cost needed to cut all the paths between the given pairs of cities.

Input

The first line of input contains two space-separated integers N, M (3 ≤ N ≤ 2 × 105) , the number of cities and the number of pairs to cut the paths between them, respectively.

The second line of input contains N space-separated integers di (0 ≤ di ≤ 109), the ith value represents the cost of destroying the ith road (or 0 if it is already destroyed).

It is guaranteed that at least one of the roads is already destroyed.

Each of the following M lines contains two space-separated integers u, v (1 ≤ u, v ≤ N) (u ≠ v), representing a pair of cities that should not remain connected. No pair of cities will appear more than once.

Output

Print the minimum cost on a single line.

ExamplesInput
4 2
1 0 1 1
1 4
2 3
Output
1
Input
8 5
4 0 5 4 5 6 3 0
1 8
3 6
5 8
8 4
4 1
Output
5

加入题单

算法标签: