Language: C++

#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL

int arr[100005];

struct comp {
	bool operator<(const int &a, const int &b) {
		return arr[a] < arr[b];
	}
};

int main() {
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i = 0; i < n; i++) {
		scanf("%d",&arr[i]);
	}
	vii graph(n+2,vi());
	for(int i = 0; i < m; i++) {
		int x,y;
		scanf("%d %d",&x,&y);
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	int next = 0;
	vector<multiset<int> > trees;
	int ind = 0;
	vector<bool> was (n+2,false);
	vector<int> intree(n+2,0);
	while(next != n) {
		while(next < n && was[next]) {
			next++;
		}
		if(next == n) {
			break;
		}
		trees.push_back(multiset<int>());
		stack<int> st;
		st.push(next);
		was[next] = true;
		while(!st.empty()) {
			int v = st.top();
			st.pop();
			trees[ind].insert(v);
			intree[v] = ind;
			for(int u : graph[v]) {
				if(!was[u]) {
					was[u] = true;
					st.push(u);
				}
			}
		}
		ind++;
	}
	if(n < 2*ind-2) {
		cout << "Impossible";
		return 0;
	}
	multiset<int> curr;
	set<int,comp> ot;
	for(int el : trees[0]) {
		curr.insert(arr[el]);
	}
	for(int i = 1; i < ind; i++) {
		for(int el : trees[i]) {
			ot.insert(el);
		}
	}
	ll ans = 0;
	while(!ot.empty()) {
		int best = (*curr.begin());
		curr.erase(curr.begin());
		int v = *(ot.begin());
		for(int el : trees[intree[v]]) {
			curr.insert(arr[el]);
			ot.erase(el);
		}
		curr.erase(curr.find(arr[v]));
		ans+= best+arr[v];
	}
	printf("%lld",ans);
	return 0;
}



Compiler output:
a.cc:14:14: error: 'bool comp::operator<(const int&, const int&)' must have exactly one argument
   14 |         bool operator<(const int &a, const int &b) {
      |              ^~~~~~~~
In file included from /usr/include/c++/14/map:62,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_tree.h: In instantiation of 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = comp; _Alloc = std::allocator<int>; key_type = int]':
/usr/include/c++/14/bits/stl_tree.h:2169:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = const int&; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = comp; _Alloc = std::allocator<int>]'
 2169 |         = _M_get_insert_unique_pos(_KeyOfValue()(__v));
      |           ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:514:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = int; _Compare = comp; _Alloc = std::allocator<int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, comp, std::allocator<int> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<int>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<int>, int>::rebind<int>; typename _Alloc::value_type = int; value_type = int]'
  514 |           _M_t._M_insert_unique(__x);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~
a.cc:73:13:   required from here
   73 |                         ot.insert(el);
      |                         ~~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_tree.h:2116:42: error: no match for call to '(comp) (const std::_Rb_tree<int, int, std::_Identity<int>, comp, std::allocator<int> >::key_type&, const int&)'
 2116 |           __comp = _M_impl._M_key_compare(__k, _S_key(__x));
      |                    ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:2127:33: error: no match for call to '(comp) (const int&, const std::_Rb_tree<int, int, std::_Identity<int>, comp, std::allocator<int> >::key_type&)'
 2127 |       if (_M_impl._M_key_compare(_S_key(__j._M_node), __k))
      |           ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h: In instantiation of 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_(_Base_ptr, _Base_ptr, _Arg&&, _NodeGen&) [with _Arg = const int&; _NodeGen = std::_Rb_tree<int, int, std::_Identity<int>, comp, std::allocator<int> >::_Alloc_node; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = comp; _Alloc = std::allocator<int>; iterator = std::_Rb_tree<int, int, std::_Identity<int>, comp, std::allocator<int> >::iterator; _Base_ptr = std::_Rb_tree_node_base*]':
/usr/include/c++/14/bits/stl_tree.h:2174:26:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = const int&; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = comp; _Alloc = std::allocator<int>]'
 2174 |           return _Res(_M_insert_(__res.first, __res.second,
      |                       ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
 2175 |                                  _GLIBCXX_FORWARD(_Arg, __v), __an),
      |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:514:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = int; _Compare = comp; _Alloc = std::allocator<int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, comp, std::allocator<int> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<int>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<int>, int>::rebind<int>; typename _Alloc::value_type = int; value_type = int]'
  514 |           _M_t._M_insert_unique(__x);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~
a.cc:73:13:   required from here
   73 |                         ot.insert(el);
      |                         ~~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_tree.h:1824:56: error: no match for call to '(comp) (const int&, const int&)'
 1824 |                               || _M_impl._M_key_compare(_KeyOfValue()(__v),
      |                                  ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
 1825 |                                                         _S_key(__p)));
      |                                                         ~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h: In instantiation of 'std::pair<std::_Rb_tree_iterator<_Val>, std::_Rb_tree_iterator<_Val> > std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::equal_range(const _Key&) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = comp; _Alloc = std::allocator<int>]':
/usr/include/c++/14/bits/stl_tree.h:2517:49:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::erase(const _Key&) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = comp; _Alloc = std::allocator<int>; size_type = long unsigned int]'
 2517 |       pair<iterator, iterator> __p = equal_range(__x);
      |                                      ~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_set.h:687:26:   required from 'std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::erase(const key_type&) [with _Key = int; _Compare = comp; _Alloc = std::allocator<int>; size_type = long unsigned int; key_type = int]'
  687 |       { return _M_t.erase(__x); }
      |                ~~~~~~~~~~^~~~~
a.cc:83:12:   required from here
   83 |                         ot.erase(el);
      |                         ~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_tree.h:2016:37: error: no match for call to '(comp) (const int&, const int&)'
 2016 |           if (_M_impl._M_key_compare(_S_key(__x), __k))
      |               ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:2018:42: error: no match for call to '(comp) (const int&, const int&)'
 2018 |           else if (_M_impl._M_key_compare(__k, _S_key(__x)))
      |                    ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(_Const_Link_type) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = comp; _Alloc = std::allocator<int>; _Const_Link_type = const std::_Rb_tree_node<int>*]':
/usr/include/c++/14/bits/stl_tree.h:2116:47:   required from 'std::pair<std::_Rb_tree_node_base*, std::_Rb_tree_node_base*> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_get_insert_unique_pos(const key_type&) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = comp; _Alloc = std::allocator<int>; key_type = int]'
 2116 |           __comp = _M_impl._M_key_compare(__k, _S_key(__x));
      |                                                ~~~~~~^~~~~
/usr/include/c++/14/bits/stl_tree.h:2169:4:   required from 'std::pair<std::_Rb_tree_iterator<_Val>, bool> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_insert_unique(_Arg&&) [with _Arg = const int&; _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = comp; _Alloc = std::allocator<int>]'
 2169 |         = _M_get_insert_unique_pos(_KeyOfValue()(__v));
      |           ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_set.h:514:25:   required from 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = int; _Compare = comp; _Alloc = std::allocator<int>; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<int, int, std::_Identity<int>, comp, std::allocator<int> >::const_iterator; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other = std::allocator<int>; typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key> = __gnu_cxx::__alloc_traits<std::allocator<int>, int>::rebind<int>; typename _Alloc::value_type = int; value_type = int]'
  514 |           _M_t._M_insert_unique(__x);
      |           ~~~~~~~~~~~~~~~~~~~~~^~~~~
a.cc:73:13:   required from here
   73 |                         ot.insert(el);
      |                         ~~~~~~~~~^~~~
/usr/include/c++/14/bits/stl_tree.h:760:23: error: static assertion failed: comparison object must be invocable with two arguments of key type
  760 |         static_assert(__is_invocable<_Compare&, const _Key&, const _Key&>{},
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_tree.h:760:23: note: 'std::__is_invocable<comp&, const int&, const int&>()' evaluates to false