Nova Poshta
"Nova Poshta" is a rapid delivery service for goods and cargo. The service operates through N warehouses, which are interconnected by M existing and licensed routes. Each route connects exactly two warehouses.
To ensure seamless operations, additional routes may need to be established so that any two warehouses can be connected directly or indirectly through other warehouses. The cost of obtaining a license at each of the N warehouses is specified in the array C[1..N]. To open a new route between warehouses i and j, licenses must be acquired at both warehouses, incurring a total cost of C[i] + C[j].
Determine the minimum total cost required to enable full operational connectivity for the "Nova Poshta" delivery service.
Input
The first line contains the integers N and M, where 0 ≤ N ≤ 1000. The second line lists N elements of the array C[1..N], with 0 ≤ C_{i} ≤ 1000000. The following M lines each contain a pair of numbers representing the already established routes. All numbers are natural numbers.
Output
Output the minimum cost necessary to ensure full operational connectivity for the delivery service.