Language: C++

#include<iostream>
11;rgb:0000/0000/0000#include<cstdio>
#include<algorithm>
#include<vector>
#include<stack>
using namespace std;

long long a[100000];
vector<int> edges[100000];

int main(){
    int N, M;
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    for(int i = 0; i < M; i++){
        int x, y;
        cin >> x >> y;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }

    if(M == N-1){
        cout << 0 << endl;
        return 0;
    }
    if(N < 2*(N-M-1)){
        cout << "Impossible" << endl;
        return 0;
    }

    long long ans = 0;
    int conn_comp_cnt = 0;
    bool visited[100000] = {};
    for(int i = 0; i < N; i++){
        if(!visited[i]){
            int shortest_index = i;
            stack<int> st;
            st.push(i);
            while(!st.empty()){
                int now = st.top(); st.pop();
                visited[now] = true;
                if(a[shortest_index] > a[now]){
                    shortest_index = now;
                }
                for(int j = 0; j < edges[i].size(); j++){
                    if(!visited[edges[now][j]]){
                        st.push(edges[now][j]);
                    }
                }
            }
            ans += a[shortest_index];
            a[shortest_index] += 1000000000;
            conn_comp_cnt++;
        }
    }
    sort(a, a+N);
    for(int i = 0; i < 2*(N-M-1) - conn_comp_cnt; i++){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;

}

Compiler output:
a.cc:2:22: error: stray '#' in program
    2 | 11;rgb:0000/0000/0000#include<cstdio>
      |                      ^
a.cc:2:1: error: expected unqualified-id before numeric constant
    2 | 11;rgb:0000/0000/0000#include<cstdio>
      | ^~
a.cc:2:4: error: 'rgb' does not name a type
    2 | 11;rgb:0000/0000/0000#include<cstdio>
      |    ^~~
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h: In function 'bool std::all_of(_InputIterator, _InputIterator, _Predicate)':
/usr/include/c++/14/bits/stl_algo.h:411:29: error: 'find_if_not' is not a member of 'std'
  411 |     { return __last == std::find_if_not(__first, __last, __pred); }
      |                             ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h: In function 'bool std::none_of(_InputIterator, _InputIterator, _Predicate)':
/usr/include/c++/14/bits/stl_algo.h:429:40: error: 'find_if' is not a member of 'std'
  429 |     { return __last == _GLIBCXX_STD_A::find_if(__first, __last, __pred); }
      |                                        ^~~~~~~
/usr/include/c++/14/bits/stl_algo.h: In function 'bool std::is_sorted(_ForwardIterator, _ForwardIterator)':
/usr/include/c++/14/bits/stl_algo.h:3192:19: error: 'is_sorted_until' is not a member of 'std'
 3192 |     { return std::is_sorted_until(__first, __last) == __last; }
      |                   ^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h: In function 'bool std::is_sorted(_ForwardIterator, _ForwardIterator, _Compare)':
/usr/include/c++/14/bits/stl_algo.h:3208:19: error: 'is_sorted_until' is not a member of 'std'
 3208 |     { return std::is_sorted_until(__first, __last, __comp) == __last; }
      |                   ^~~~~~~~~~~~~~~