You are given a forest with N vertices and M edges. The vertices are numbered 0 through N−1. The edges are given in the format (x_i,y_i), which means that vertex x_i and y_i are connected by an edge.
Each vertex i is assigned value a_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 i and j, then span an edge between i and j. This operation costs a_i+a_j dollars, and afterward neither vertex i nor j 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:
N M
a_0 a_1 … a_N−1
x_1 y_1
…
x_M y_M
Print the minimum total cost required to make the forest connected, or print "Impossible" if it is impossible.
1≤N≤100,000, 0≤M≤N−1, 1≤a_i≤109, 0≤x_i,y_i≤N−1. The given graph is a forest. All input values are integers.
In Sample 1, if we connect vertices 0 and 5, the graph become connected, and the cost is 1+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.