Forest Task

아직 제출이 없습니다시간 제한2초메모리 제한256 MB

문제

You are given a forest with NN vertices and MM edges. The vertices are numbered 00 through N1N-1. The edges are given in the format (x_i,y_i)(x\_i,y\_i), which means that vertex x_ix\_i and y_iy\_i are connected by an edge.

Each vertex ii is assigned value a_ia\_i. You want to add edges in the given forest so that the forest becomes connected. To add an edge, you choose two different vertices ii and jj, then span an edge between ii and jj. This operation costs a_i+a_ja\_i + a\_j dollars, and afterward neither vertex ii nor jj can be selected again.

Find the minimum total cost required to make the forest connected, or print "Impossible" if it is impossible.

입력

Input is given in the following format:

NN MM

a_0a\_0 a_1a\_1 \ldots a_N1a\_{N-1}

x_1x\_1 y_1y\_1

\ldots

x_Mx\_M y_My\_M

출력

Print the minimum total cost required to make the forest connected, or print "Impossible" if it is impossible.

제한

1N100,0001 \le N \le 100\\,000, 0MN10 \le M \le N-1, 1a_i1091 \le a\_i \le 10^9, 0x_i,y_iN10 \le x\_i,y\_i \le N-1. The given graph is a forest. All input values are integers.

힌트

In Sample 1, if we connect vertices 00 and 55, the graph become connected, and the cost is 1+6=71 + 6 = 7.

In Sample 2, we can't make the graph connected.

In Sample 3, the graph is connected, regardless of whether we do something or not.