Language: C++

#include<bits/stdc++.h>
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-funroll-loops")
#pragma GCC target("avx,sse4")
#define mms(a,n) memset(a,0,sizeof((a)[0])*(n))
#define mmp(a,b,n) memcpy(a,b,sizeof((b)[0])*(n))
#define lowbit(x) ((x)&-(x))
#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
#define fd(i,r,l) for(register int i=r,_lim_=l;i>=_lim_;i--)
#define fos(i,l,r,d) for(register int i=l,_lim_=r;i<=r;i+=d)
#define fol(i,l,r) for(register ll i=l,_lim_=r;i<=_lim_;i++)
#define fdl(i,r,l) for(register ll i=r,_lim_=l;i>=_lim_;i--)
#define fosl(i,l,r,d) for(register ll i=l,_lim_=r;i<=r;i+=d)
#define Clear(a) memset(a,0,sizeof(a))
#define Copy(a,b) memcpy(a,b,sizeof(b))
#define ALL(v) v.begin(),v.end() #define SZ(v) ((int)v.size())
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ldb;
typedef double db;
typedef pair<int,int> pi;
const int N=100005;
int n,m,a[N],fa[N],blk;
vector<int>e[N],E; ll ans;
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main(){
    scanf("%d%d",&n,&m);
    fo(i,1,n)scanf("%d",&a[i]),fa[i]=i,blk++;
    for(int i=1,u,v;i<=m;i++){
        scanf("%d%d",&u,&v);u++;v++;
        if(find(u)!=find(v))
        fa[find(u)]=find(v),blk--;
    } fo(i,1,n)e[find(i)].pb(a[i]);
    if(blk==1)puts("0"),exit(0);
    int cur=blk-2;
    fo(i,1,n)
        if(e[i].size()){
            sort(ALL(e[i]));
            ans+=e[i][0];
            fo(j,1,int(e[i].size())-1)E.pb(e[i][j]);
        }
    sort(ALL(E));
    if(cur>E.size())puts("Impossible"),exit(0);
    fo(i,0,cur-1)ans+=E[i];
    cout<<ans<<endl; return 0;
}




Compiler output:
a.cc:20:14: error: '#' is not followed by a macro parameter
   20 | #define ALL(v) v.begin(),v.end() #define SZ(v) ((int)v.size())
      |              ^
a.cc: In function 'int main()':
a.cc:33:8: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   33 |     fo(i,1,n)scanf("%d",&a[i]),fa[i]=i,blk++;
      |        ^
a.cc:12:36: note: in definition of macro 'fo'
   12 | #define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
      |                                    ^
a.cc:12:40: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 | #define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
      |                                        ^~~~~
a.cc:33:5: note: in expansion of macro 'fo'
   33 |     fo(i,1,n)scanf("%d",&a[i]),fa[i]=i,blk++;
      |     ^~
a.cc:38:10: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   38 |     } fo(i,1,n)e[find(i)].pb(a[i]);
      |          ^
a.cc:12:36: note: in definition of macro 'fo'
   12 | #define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
      |                                    ^
a.cc:12:40: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 | #define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
      |                                        ^~~~~
a.cc:38:7: note: in expansion of macro 'fo'
   38 |     } fo(i,1,n)e[find(i)].pb(a[i]);
      |       ^~
a.cc:41:8: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   41 |     fo(i,1,n)
      |        ^
a.cc:12:36: note: in definition of macro 'fo'
   12 | #define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
      |                                    ^
a.cc:12:40: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 | #define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
      |                                        ^~~~~
a.cc:41:5: note: in expansion of macro 'fo'
   41 |     fo(i,1,n)
      |     ^~
a.cc:43:18: error: 'ALL' was not declared in this scope
   43 |             sort(ALL(e[i]));
      |                  ^~~
a.cc:45:16: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   45 |             fo(j,1,int(e[i].size())-1)E.pb(e[i][j]);
      |                ^
a.cc:12:36: note: in definition of macro 'fo'
   12 | #define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
      |                                    ^
a.cc:12:40: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 | #define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
      |                                        ^~~~~
a.cc:45:13: note: in expansion of macro 'fo'
   45 |             fo(j,1,int(e[i].size())-1)E.pb(e[i][j]);
      |             ^~
a.cc:47:10: error: 'ALL' was not declared in this scope
   47 |     sort(ALL(E));
      |          ^~~
a.cc:49:8: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   49 |     fo(i,0,cur-1)ans+=E[i];
      |        ^
a.cc:12:36: note: in definition of macro 'fo'
   12 | #define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
      |                                    ^
a.cc:12:40: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   12 | #define fo(i,l,r) for(register int i=l,_lim_=r;i<=_lim_;i++)
      |                                        ^~~~~
a.cc:49:5: note: in expansion of macro 'fo'
   49 |     fo(i,0,cur-1)ans+=E[i];
      |     ^~