Language: C++


//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define swap(p,q) r=(p);(p)=(q);(q)=r
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007//10^9+7
#define PI acos(-1)

using namespace std;


static int come[100010];
int solonum=0;
int cnt=0;
static vector<int> graph[100010];
int solo[100010];
static vector<int> subtree[100010];


int search(int x){
	int i;

	if(come[x]==1) return 0;

	come[x]=1;

	subtree[cnt].push_back(x);

	for(i=0;i<graph[x].size();i++){
		search(graph[x][i]);
	}

	return 0;
}


struct cost_t {
	int idnum;
	int cost;
} ;

int compare_cost(const void *a, const void *b) {
	struct cost_t *A = (struct cost_t *)a;
	struct cost_t *B = (struct cost_t *)b;
	return A->cost - B->cost;
}

struct subtree_min_t {
	int idnum;
	int cost;
} ;

int compare_min(const void *a, const void *b) {
	struct subtree_min_t *A = (struct subtree_min_t *)a;
	struct subtree_min_t *B = (struct subtree_min_t *)b;
	return A->cost - B->cost;
}

int main(void)
{
	//変数の宣言
	int n,m;
	int x,y;
	//	vector<int> graph[100010];
	//	int solo[100010];
	multiset<int> maintree;
	static int use[100010];
	static struct cost_t ct[100010];
	static int inv[100010];
	//	vector<int> subtree[100010];
	//	static int come[100010];
	static struct cost_t memo[100010]; 
	int mt;

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	ll int ans=0;
	//	int cnt=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;



	//データの読み込み


	scanf("%d %d",&n,&m);
//	scanf_s("%d %d",&n,&m);

	for(i=0;i<n;i++){
		scanf("%d",&ct[i].cost);
//		scanf_s("%d",&ct[i].cost);
		ct[i].idnum=i;
	}

	qsort(ct, n, sizeof(struct cost_t), compare_cost);

	for(i=0;i<n;i++){
		inv[ct[i].idnum]=i;
	}

	for(i=0;i<m;i++){
		scanf("%d %d",&x,&y);
//		scanf_s("%d %d",&x,&y);
		graph[inv[x]].push_back(inv[y]);
		graph[inv[y]].push_back(inv[x]);
	}

	for(i=0;i<n+1;i++){
		come[i]=0;
		subtree_min[i].cost=0;
	}

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	i=0;
	while(i<n){
		search(i);
		cnt++;

		while(1==come[i]){
			i++;
		}
	}

	for(i=0;i<cnt;i++){
		for(j=0;j<subtree[i].size();j++){
			memo[j].idnum=subtree[i][j];
			memo[j].cost=ct[subtree[i][j]].cost;
		}

		qsort(memo, subtree[i].size(), sizeof(struct cost_t), compare_cost);
		ans=ans+memo[0].cost;
		for(j=1;j<subtree[i].size();j++){
			maintree.insert(subtree[i][j]);
		}
	}

	if(cnt==1){
		printf("0");
		return 0;
	}else if(cnt>2&&maintree.size()<cnt-2){
		printf("Impossible");
		return 0;
	}else{
		auto itr=maintree.begin();
		for(i=0;i<cnt-2;i++){
			mt=*itr;
			ans=ans+mt;
		}
	}



	//	printf("計算部分終了\n");

	//出力

	printf("%lld",ans);

	//	printf("結果の出力終了\n");


	return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:134:17: error: 'subtree_min' was not declared in this scope; did you mean 'subtree_min_t'?
  134 |                 subtree_min[i].cost=0;
      |                 ^~~~~~~~~~~
      |                 subtree_min_t