Language: C++

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
const int maxn=100005;
struct data{
    int id,val;
    bool operator <(const data& x) const{
        return val>x.val;
    }
};
int fa[maxn],a[maxn];
int num[maxn];
int Find(int x){return fa[x]==x?fa[x]:fa[x]=Find(fa[x]);}
void unionxy(int x,int y){
    int xx=Find(x),yy=Find(y);
    if(xx==yy) return ;
    else Far[xx]=yy;
}
std::priority_queue<data>q;
__gnu_pbds::priority_queue<int,greater<int>,binomial_heap_tag> q1[maxn];
int main(){
    //freopen("in.txt","r",stdin);
    int m,n;
    scanf("%d%d",&n,&m);
    for(int i=0;i<=n;i++) fa[i]=i;
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    int u,v;
    for(int i=1;i<=m;i++){scanf("%d%d",&u,&v);unionxy(u,v);}
    for(int i=0;i<n;i++){
        num[Find(i)]++;
        q1[Find(i)].push(a[i]);
    }
    int sum=0,sum1=0;
    for(int i=0;i<n;i++){
        if(q1[i].size()){
            sum++;sum1+=num[i];
            data tmp={i,q1[i].top()};
            q.push(tmp);
        }
    }
    if((sum-1)*2>sum1){puts("impossible");return 0;}
    ll ans=0;
    int cnt=0;
    while(!q.empty()){
        if(cnt==sum-1) break;
        data u=q.top();q.pop();
        data v=q.top();q.pop();
        ans+=(u.val+v.val);
        unionxy(u.id,v.id);
        q1[v.id].join(q1[u.id]);
        q.push({v.id,q1[v.id].top()});
        cnt++;
    }
    printf("%lld\n",ans);
    return 0;
}


Compiler output:
a.cc: In function 'void unionxy(int, int)':
a.cc:20:10: error: 'Far' was not declared in this scope
   20 |     else Far[xx]=yy;
      |          ^~~
a.cc: At global scope:
a.cc:22:25: error: template argument 1 is invalid
   22 | std::priority_queue<data>q;
      |                         ^
a.cc:22:25: error: template argument 2 is invalid
a.cc:22:25: error: template argument 3 is invalid
a.cc: In function 'int main()':
a.cc:40:13: error: reference to 'data' is ambiguous
   40 |             data tmp={i,q1[i].top()};
      |             ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:8:8: note:                 'struct data'
    8 | struct data{
      |        ^~~~
a.cc:41:15: error: request for member 'push' in 'q', which is of non-class type 'int'
   41 |             q.push(tmp);
      |               ^~~~
a.cc:41:20: error: 'tmp' was not declared in this scope; did you mean 'tm'?
   41 |             q.push(tmp);
      |                    ^~~
      |                    tm
a.cc:47:14: error: request for member 'empty' in 'q', which is of non-class type 'int'
   47 |     while(!q.empty()){
      |              ^~~~~
a.cc:49:9: error: reference to 'data' is ambiguous
   49 |         data u=q.top();q.pop();
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:8:8: note:                 'struct data'
    8 | struct data{
      |        ^~~~
a.cc:49:26: error: request for member 'pop' in 'q', which is of non-class type 'int'
   49 |         data u=q.top();q.pop();
      |                          ^~~
a.cc:50:9: error: reference to 'data' is ambiguous
   50 |         data v=q.top();q.pop();
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:8:8: note:                 'struct data'
    8 | struct data{
      |        ^~~~
a.cc:50:26: error: request for member 'pop' in 'q', which is of non-class type 'int'
   50 |         data v=q.top();q.pop();
      |                          ^~~
a.cc:51:17: error: request for member 'val' in 'u', which is of non-class type 'int'
   51 |         ans+=(u.val+v.val);
      |                 ^~~
a.cc:51:23: error: request for member 'val' in 'v', which is of non-class type 'int'
   51 |         ans+=(u.val+v.val);
      |                       ^~~
a.cc:52:19: error: request for member 'id' in 'u', which is of non-class type 'int'
   52 |         unionxy(u.id,v.id);
      |                   ^~
a.cc:52:24: error: request for member 'id' in 'v', which is of non-class type 'int'
   52 |         unionxy(u.id,v.id);
      |                        ^~
a.cc:53:14: error: request for member 'id' in 'v', which is of non-class type 'int'
   53 |         q1[v.id].join(q1[u.id]);
      |              ^~
a.cc:53:28: error: request for member 'id' in 'u', which is of non-class type 'int'
   53 |         q1[v.id].join(q1[u.id]);
      |                            ^~
a.cc:54:11: error: request for member 'push' in 'q', which is of non-class type 'int'
   54 |         q.push({v.id,q1[v.id].top()});
      |           ^~~~
a.cc:54:19: error: request for member 'id' in 'v', which is of non-class type 'int'
   54 |         q.push({v.id,q1[v.id].top()});
      |                   ^~
a.cc:54:27: error: request for member 'id' in 'v', which is of non-class type 'int'
   54 |         q.push({v.id,q1[v.id].top()});
      |                           ^~