Language: C++

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<list>
#define ull unsigned long long 
#define ll long long 
#define pii pair<int,int >
#define iiii pair<int,pii >
#define MAXN 100020
 
using namespace std;

int X[MAXN],Y[MAXN],par[MAXN],rank[MAXN];
vector<pii >vX,vY;
set<pair<int,pii > >Set;
ll res=0;
int n;

void fInit(int n)
{
	for(int i=0;i<n;i++)
	{
		par[i]=i;
		rank[i]=0;
	}
}

int fFind(int x)
{
	if(par[x]==x) return x;
	return par[x]=fFind(par[x]);
}

ll fUnite(int x,int y)
{
	x=fFind(x);y=fFind(y);
	if(x==y)return false;
	if(rank[x]<rank[y])par[x]=y;
	else
	{
		par[y]=x;
		if(rank[x]==rank[y])rank[x]++;
	}
	return 1;
}

int know(int x,int y)
{
	return abs(x-y);
}

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",X+i,Y+i);
		vX.push_back(make_pair(X[i],i));
		vY.push_back(make_pair(Y[i],i));
	}
	
	fInit(n);
	sort(vX.begin(),vX.end());
	sort(vY.begin(),vY.end());
	
	for(int i=0;i<n-1;i++)
	{
		Set.insert(make_pair(know(vX[i+1].first,vX[i].first),make_pair(vX[i+1].second,vX[i].second)));
		Set.insert(make_pair(know(vY[i+1].first,vY[i].first),make_pair(vY[i+1].second,vY[i].second)));
	}
	
	while (Set.size())
	{
		set<iiii >::iterator it=Set.begin();
		res+=fUnite((*it).second.second,(*it).second.first)*(ll)(*it).first;
		Set.erase(it);
	}
	
	cout<<res<<endl;
	
	return 0;	
} 

Compiler output:
a.cc: In function 'void fInit(int)':
a.cc:35:17: error: reference to 'rank' is ambiguous
   35 |                 rank[i]=0;
      |                 ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:24:31: note:                 'int rank [100020]'
   24 | int X[MAXN],Y[MAXN],par[MAXN],rank[MAXN];
      |                               ^~~~
a.cc: In function 'long long int fUnite(int, int)':
a.cc:49:12: error: reference to 'rank' is ambiguous
   49 |         if(rank[x]<rank[y])par[x]=y;
      |            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:24:31: note:                 'int rank [100020]'
   24 | int X[MAXN],Y[MAXN],par[MAXN],rank[MAXN];
      |                               ^~~~
a.cc:49:20: error: reference to 'rank' is ambiguous
   49 |         if(rank[x]<rank[y])par[x]=y;
      |                    ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:24:31: note:                 'int rank [100020]'
   24 | int X[MAXN],Y[MAXN],par[MAXN],rank[MAXN];
      |                               ^~~~
a.cc:53:20: error: reference to 'rank' is ambiguous
   53 |                 if(rank[x]==rank[y])rank[x]++;
      |                    ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:24:31: note:                 'int rank [100020]'
   24 | int X[MAXN],Y[MAXN],par[MAXN],rank[MAXN];
      |                               ^~~~
a.cc:53:29: error: reference to 'rank' is ambiguous
   53 |                 if(rank[x]==rank[y])rank[x]++;
      |                             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:24:31: note:                 'int rank [100020]'
   24 | int X[MAXN],Y[MAXN],par[MAXN],rank[MAXN];
      |                               ^~~~
a.cc:53:37: error: reference to 'rank' is ambiguous
   53 |                 if(rank[x]==rank[y])rank[x]++;
      |                                     ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:24:31: note:                 'int rank [100020]'
   24 | int X[MAXN],Y[MAXN],par[MAXN],rank[MAXN];
      |                               ^~~~