Language: C++

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)

struct city{
		int x,y,i;
		city(int x_,int y_,int i_){
			x=x_,y=y_,i=i_;
		};

};

struct edge{
			int cst,e1,e2;
		edge(int cst_,int e1_,int e2_){
			cst=cst_,e1=e1_,e2=e2_;
		};
		bool operator<(const edge& o)const{cst>o.cst;}			
};

struct unionFind{
	size_t n;
	vector<int> pr;
	unionFind(size_t n_){
		n=n_;
		pr.resize(n,-1);
	};
	int root(int a){
		if(pr[a]==-1)return a;
		else return pr[a]=root(pr[a]);
	}
	void unify(int a,int b){
		a=root(a);b=root(b);
		if(a==b)return;
		pr[b]=a;
	}
	bool same(int a,int b){return root(a)==root(b);}
};


signed main(){
	size_t n;cin>>n;
	vector<city>c(n);
	rep(i,n){cin>>c[i].x>>c[i].y;c[i].i=i;}
	priority_queue<edge> pq;
	sort(begin(c),end(c),[&](city a,city b){return a.x<b.x;});
	rep(i,n-1)pq.push(edge(c[i+1].x-c[i].x,c[i].i,c[i+1].i));

	sort(begin(c),end(c),[&](city a,city b){return a.y<b.y;});
	rep(i,n-1)pq.push(edge(c[i+1].y-c[i].y,c[i].i,c[i+1].i));

	unionFind uf(n);
	int cnt=0,sm=0;
	while(!pq.empty()){
	edge x=pq.top();pq.pop();
		if(uf.same(x.e1,x.e2))continue;
		uf.unify(x.e1,x.e2);
		cnt++;sm+=x.cst;	
		if(cnt==n-1)break;
	}	
	cout<<sm<<endl;

	
	
	 
}

Compiler output:
a.cc: In member function 'bool edge::operator<(const edge&) const':
a.cc:19:62: warning: no return statement in function returning non-void [-Wreturn-type]
   19 |                 bool operator<(const edge& o)const{cst>o.cst;}
      |                                                              ^
In file included from /usr/include/c++/14/bits/stl_tempbuf.h:61,
                 from /usr/include/c++/14/bits/stl_algo.h:69,
                 from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_construct.h: In instantiation of 'void std::_Construct(_Tp*, _Args&& ...) [with _Tp = city; _Args = {}]':
/usr/include/c++/14/bits/stl_uninitialized.h:643:18:   required from 'static _ForwardIterator std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator, _Size) [with _ForwardIterator = city*; _Size = long unsigned int; bool _TrivialValueType = false]'
  643 |                 std::_Construct(std::__addressof(*__cur));
      |                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:712:20:   required from '_ForwardIterator std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator = city*; _Size = long unsigned int]'
  710 |       return __uninitialized_default_n_1<__is_trivial(_ValueType)
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  711 |                                          && __can_fill>::
      |                                          ~~~~~~~~~~~~~~~~
  712 |         __uninit_default_n(__first, __n);
      |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_uninitialized.h:779:44:   required from '_ForwardIterator std::__uninitialized_default_n_a(_ForwardIterator, _Size, allocator<_Tp>&) [with _ForwardIterator = city*; _Size = long unsigned int; _Tp = city]'
  779 |     { return std::__uninitialized_default_n(__first, __n); }
      |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1720:36:   required from 'void std::vector<_Tp, _Alloc>::_M_default_initialize(size_type) [with _Tp = city; _Alloc = std::allocator<city>; size_type = long unsigned int]'
 1720 |           std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1721 |                                            _M_get_Tp_allocator());
      |                                            ~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:558:9:   required from 'std::vector<_Tp, _Alloc>::vector(size_type, const allocator_type&) [with _Tp = city; _Alloc = std::allocator<city>; size_type = long unsigned int; allocator_type = std::allocator<city>]'
  558 |       { _M_default_initialize(__n); }
      |         ^~~~~~~~~~~~~~~~~~~~~
a.cc:44:17:   required from here
   44 |         vector<city>c(n);
      |                        ^
/usr/include/c++/14/bits/stl_construct.h:119:7: error: no matching function for call to 'city::city()'
  119 |       ::new((void*)__p) _Tp(std::forward<_Args>(__args)...);
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:8:17: note: candidate: 'city::city(long long int, long long int, long long int)'
    8 |                 city(int x_,int y_,int i_){
      |                 ^~~~
a.cc:8:17: note:   candidate expects 3 arguments, 0 provided
a.cc:6:8: note: candidate: 'constexpr city::city(const city&)'
    6 | struct city{
      |        ^~~~
a.cc:6:8: note:   candidate expects 1 argument, 0 provided
a.cc:6:8: note: candidate: 'constexpr city::city(city&&)'
a.cc:6:8: note:   candidate expects 1 argument, 0 provided