Language: C++

#include <bits/stdc++.h>
using namespace std;
long long ans;
int n,fa[100003],r[100003];
pair<int,int> a[100003],x[100003],y[100003];
priority_queue <pair<int,pair<int,int> > > q;
int find_fa(int x){
	if(fa[x]==x) return x;
	return fa[x]=find_fa(fa[x]);
}
void uni(int x,int y){
	x=find_fa(x);
	y=find_fa(y);
	if (r[x]<r[y]) fa[x]=y;
	else{
		fa[y]=x;
		if(r[x]==r[y]) r[x]++;
	}
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++) fa[i]=i;
	for(int i=0;i<n;i++){
		cin>>a[i].fi>>a[i].second;
		x[i]={a[i].fi,i};
		y[i]={a[i].second,i};
	}
	sort(x,x+n);
	sort(y,y+n);
	for(int i=0;i<n-1;i++){
		q.push({-(x[i+1].fi-x[i].fi),{x[i].second,x[i+1].second}});
		q.push({-(y[i+1].fi-y[i].fi),{y[i].second,y[i+1].second}});
	}
	while(q.size()){
		int c=-q.top().fi,p1=q.top().second.fi,p2=q.top().second.second;
		if(find_fa(p1)!=find_fa(p2)){
			uni(p1,p2);
			ans+=c;
		}
		q.pop();
	}
	cout<<ans;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:27: error: 'struct std::pair<int, int>' has no member named 'fi'
   24 |                 cin>>a[i].fi>>a[i].second;
      |                           ^~
a.cc:25:28: error: 'struct std::pair<int, int>' has no member named 'fi'
   25 |                 x[i]={a[i].fi,i};
      |                            ^~
a.cc:25:32: error: no match for 'operator=' (operand types are 'std::pair<int, int>' and '<brace-enclosed initializer list>')
   25 |                 x[i]={a[i].fi,i};
      |                                ^
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_pair.h:946:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, const _U1&>, std::is_assignable<_T2&, const _U2&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U2 = _U1; _T1 = int; _T2 = int]'
  946 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:946:9: note:   template argument deduction/substitution failed:
a.cc:25:32: note:   couldn't deduce template parameter '_U1'
   25 |                 x[i]={a[i].fi,i};
      |                                ^
/usr/include/c++/14/bits/stl_pair.h:957:9: note: candidate: 'template<class _U1, class _U2> typename std::enable_if<std::__and_<std::is_assignable<_T1&, _U1&&>, std::is_assignable<_T2&, _U2&&> >::value, std::pair<_T1, _T2>&>::type std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U2 = _U1; _T1 = int; _T2 = int]'
  957 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:957:9: note:   template argument deduction/substitution failed:
a.cc:25:32: note:   couldn't deduce template parameter '_U1'
   25 |                 x[i]={a[i].fi,i};
      |                                ^
/usr/include/c++/14/bits/stl_pair.h:921:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&>) [with _T1 = int; _T2 = int; std::__conditional_t<((bool)std::__and_<std::is_copy_assignable<_T1>, std::is_copy_assignable<_T2> >::value), const std::pair<_T1, _T2>&, const std::__nonesuch&> = const std::pair<int, int>&]'
  921 |       operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:923:65: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::__conditional_t<true, const std::pair<int, int>&, const std::__nonesuch&>' {aka 'const std::pair<int, int>&'}
  921 |       operator=(__conditional_t<__and_<is_copy_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  922 |                                        is_copy_assignable<_T2>>::value,
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  923 |                                 const pair&, const __nonesuch&> __p)
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_pair.h:931:7: note: candidate: 'std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&>) [with _T1 = int; _T2 = int; std::__conditional_t<((bool)std::__and_<std::is_move_assignable<_Tp>, std::is_move_assignable<_T2> >::value), std::pair<_T1, _T2>&&, std::__nonesuch&&> = std::pair<int, int>&&]'
  931 |       operator=(__conditional_t<__and_<is_move_assignable<_T1>,
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:933:55: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::__conditional_t<true, std::pair<int, int>&&, std::__nonesuch&&>' {aka 'std::pair<int, int>&&'}
  931 |       operator=(__conditional_t<__and_<is_move_assignable<_T1>,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  932 |                                        is_move_assignable<_T2>>::value,
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  933 |                                 pair&&, __nonesuch&&> __p)
      |                                 ~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:31:34: error: 'struct std::pair<int, int>' has no member named 'fi'
   31 |                 q.push({-(x[i+1].fi-x[i].fi),{x[i].second,x[i+1].second}});
      |                                  ^~
a.cc:31:42: error: 'struct std::pair<int, int>' has no member named 'fi'
   31 |                 q.push({-(x[i+1].fi-x[i].fi),{x[i].second,x[i+1].second}});
      |                                          ^~
a.cc:31:23: error: no matching function for call to 'std::priority_queue<std::pair<int, std::pair<int, int> > >::push(<brace-enclosed initializer list>)'
   31 |                 q.push({-(x[i+1].fi-x[i].fi),{x[i].second,x[i+1].second}});
      |                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:157:
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<int, std::pair<int, int> >; _Sequence = std::vector<std::pair<int, std::pair<int, int> >, std::allocator<std::pair<int, std::pair<int, int> > > >; _Compare = std::less<std::pair<int, std::pair<int, int> > >; value_type = std::pair<int, std::pair<int, int> >]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::priority_queue<std::pair<int, std::pair<int, int> > >::value_type&' {aka 'const std::pair<int, std::pair<int, int> >&'}
  736 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = std::pair<int, std::pair<int, int> >; _Sequence = std::vector<std::pair<int, std::pair<int, int> >, std::allocator<std::pair<int, std::pair<int, int> > > >; _Compare = std::less<std::pair<int, std::pair<int, int> > >; value_type = std::pair<int, std::pair<int, int> >]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<int, std::pair<int, int> > >::value_type&&' {aka 'std::pair<int, std::pair<int, int> >&&'}
  744 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:32:34: error: 'struct std::pair<int, int>' has no member named 'fi'
   32 |                 q.push({-(y[i+1].fi-y[i].fi),{y[i].second,y[i+1].second}});
      |                                  ^~
a.cc:32:42: error: 'struct std::pair<int, int>' has no member named 'fi'
   32 |                 q.push({-(y[i+1].fi-y[i].fi),{y[i].second,y[i+1].second}});
      |                                          ^~
a.cc:32:23: error: no matching function for call to 'std::priority_queue<std::pair<int, std::pair<int, int> > >::push(<brace-enclosed initializer list>)'
   32 |                 q.push({-(y[i+1].fi-y[i].fi),{y[i].second,y[i+1].second}});
      |                 ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<int, std::pair<int, int> >; _Sequence = std::vector<std::pair<int, std::pair<int, int> >, std::allocator<std::pair<int, std::pair<int, int> > > >; _Compare = std::less<std::pair<int, std::pair<int, int> > >; value_type = std::pair<int, std::pair<int, int> >]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::priority_queue<std::pair<int, std::pair<int, int> > >::value_type&' {aka 'const std::pair<int, std::pair<int, int> >&'}
  736 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = std::pair<int, std::pair<int, int> >; _Sequence = std::vector<std::pair<int, std::pair<int, int> >, std::allocator<std::pair<int, std::pair<int, int> > > >; _Compare = std::less<std::pair<int, std::pair<int, int> > >; value_type = std::pair<int, std::pair<int, int> >]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<int, std::pair<int, int> > >::value_type&&' {aka 'std::pair<int, std::pair<int, int> >&&'}
  744 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:35:32: error: 'const __gnu_cxx::__alloc_traits<std::allocator<std::pair<int, std::pair<int, int> > >, std::pair<int, std::pair<int, int> > >::value_type' {aka 'const struct std::pair<int, std::pair<int, int> >'} has no member named 'fi'
   35 |                 int c=-q.top().fi,p1=q.top().second.fi,p2=q.top().second.second;
      |                                ^~
a.cc:36:28: error: 'p1' was not declared in this scope; did you mean 'y1'?
   36 |                 if(find_fa(p1)!=find_fa(p2)){
      |                            ^~
      |                            y1
a.cc:36:41: error: 'p2' was not declared in this scope
   36 |                 if(find_fa(p1)!=find_fa(p2)){
      |                                         ^~