Language: C++

const int maxn = 1e5+5;
int cas=1;
int fa[maxn];
int Find(int x) {
    return fa[x] == x ? x : fa[x] = Find(fa[x]);
}
priority_queue<int,vector<int>,greater<int> >q[maxn], pp;
int a[maxn];
int vis[maxn];
void solve()
{
    int n, m;
    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);
    for (int i = 1 ; i <= m ; i ++) {
        int u, v;
        scanf("%d%d", &u, &v);
        u = Find(u);
        v = Find(v);
        fa[u] = v;
    }
    int k = 0;
    for (int i = 0 ; i < n ; i ++) {
        int tmp = Find(i);
        if (!vis[tmp]) {
            vis[tmp] = ++k;
            q[k].push(a[i]);
        }
        else q[vis[tmp]].push(a[i]);
    }
    if (k == 1) {
        printf("0\n");
        return ;
    }
    ll ans = 0;
    for (int i = 1 ; i <= k ; i ++) {
        if (q[i].empty()) continue;
        ans += q[i].top();
        q[i].pop();
        while(!q[i].empty()) {
            pp.push(q[i].top());
            q[i].pop();
        }
    }
    int sum = k - 2;
    int flag = 1;
    while(sum--) {
        if (pp.empty()) {
            flag = 0;
            break;
        }
        ans += pp.top();
        pp.pop();
    }
    if (!flag) printf("Impossible\n");
    else printf("%lld\n", ans);
}

//#if def a = TreeNode(Exp a) then Preaise;

Compiler output:
a.cc:7:1: error: 'priority_queue' does not name a type
    7 | priority_queue<int,vector<int>,greater<int> >q[maxn], pp;
      | ^~~~~~~~~~~~~~
a.cc: In function 'void solve()':
a.cc:13:5: error: 'scanf' was not declared in this scope
   13 |     scanf("%d%d", &n, &m);
      |     ^~~~~
a.cc:28:13: error: 'q' was not declared in this scope
   28 |             q[k].push(a[i]);
      |             ^
a.cc:30:14: error: 'q' was not declared in this scope
   30 |         else q[vis[tmp]].push(a[i]);
      |              ^
a.cc:33:9: error: 'printf' was not declared in this scope
   33 |         printf("0\n");
      |         ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | const int maxn = 1e5+5;
a.cc:36:5: error: 'll' was not declared in this scope
   36 |     ll ans = 0;
      |     ^~
a.cc:38:13: error: 'q' was not declared in this scope
   38 |         if (q[i].empty()) continue;
      |             ^
a.cc:39:9: error: 'ans' was not declared in this scope
   39 |         ans += q[i].top();
      |         ^~~
a.cc:39:16: error: 'q' was not declared in this scope
   39 |         ans += q[i].top();
      |                ^
a.cc:42:13: error: 'pp' was not declared in this scope
   42 |             pp.push(q[i].top());
      |             ^~
a.cc:49:13: error: 'pp' was not declared in this scope
   49 |         if (pp.empty()) {
      |             ^~
a.cc:53:9: error: 'ans' was not declared in this scope
   53 |         ans += pp.top();
      |         ^~~
a.cc:53:16: error: 'pp' was not declared in this scope
   53 |         ans += pp.top();
      |                ^~
a.cc:56:16: error: 'printf' was not declared in this scope
   56 |     if (!flag) printf("Impossible\n");
      |                ^~~~~~
a.cc:56:16: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
a.cc:57:27: error: 'ans' was not declared in this scope
   57 |     else printf("%lld\n", ans);
      |                           ^~~
a.cc:57:10: error: 'printf' was not declared in this scope
   57 |     else printf("%lld\n", ans);
      |          ^~~~~~
a.cc:57:10: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'