Language: C++

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000000
int par[12345678];//親
int rnk[12345678];
void init(int n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i; rnk[i] = 0;
	}
}
//木の根を求める
int find(int x) {
	if (par[x] == x) { return x; }
	else { return par[x] = find(par[x]); }
}
//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x); y = find(y);
	if (x == y) { return; }
	if (rnk[x] < rnk[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rnk[x] == rnk[y])rnk[x]++;
	}
}
//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}
int cost[12345678], kari[12345678];
signed main() {
	int n, m, a, s, t, x = 0, y = 0, ans = 0; cin >> n >> m;
	vector<vector<int>> v(123456); vector<int> S, cnt; init(n);
	for (int h = 0; h < n; h++) {
		cin >> a; cost[h] = a;
	}
	for (int h = 0; h < m; h++) {
		cin >> s >> t; unite(s, t);
	}
	for (int h = 0; h < n; h++) {
		int z = find(h); v[z].push_back(cost[h]);
		if (kari[z] == 0) { S.push_back(z); kari[z]++; }
	}
	for (int h = 0; h < S.size(); h++) {
		sort(v[S[h]].begin(), v[S[h]].end());
	}
	if ((S.size() - 1) * 2 > n) { cout << "Impossible" << endl; return 0; }
	for (int h = 0; h < S.size(); h++) {
		ans += v[S[h]][0]; cnt.push_back(v[S[h]][0]);
	}
	sort(cnt.begin(), cnt.end()); sort(cost, cost + n);
	for (int h = 0; h < (S.size() - 1) * 2 - S.size(); h++) {
		while (cost[x] == cnt[y]) {
			x++; y++;
		}
		ans += cost[x]; x++;
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc:2:13: error: expected ',' or ';' before 'long'
    2 | #define int long long
      |             ^~~~
a.cc:5:1: note: in expansion of macro 'int'
    5 | int par[12345678];//親
      | ^~~
a.cc: In function 'void init(long long int)':
a.cc:9:17: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
    9 |                 par[i] = i; rnk[i] = 0;
      |                 ^~~
      |                 __pstl::execution::v1::par
In file included from /usr/include/c++/14/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/14/algorithm:86,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc: In function 'long long int find(long long int)':
a.cc:14:13: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   14 |         if (par[x] == x) { return x; }
      |             ^~~
      |             __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc: In function 'void unite(long long int, long long int)':
a.cc:22:17: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   22 |                 par[x] = y;
      |                 ^~~
      |                 __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc:25:17: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   25 |                 par[y] = x;
      |                 ^~~
      |                 __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~