Language: C++

#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n;
P p[100001];
vector<int> y[100001];
vector<int> xi;
vector<P> query;
vector<PP> edge;
int rank[100001];
int par[100001];

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

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

void unite(int x,int y){
	x=find(x);
	y=find(y);
	if(x==y)return;
	if(rank[x]<rank[y]){
		par[x]=y;
	}else{
		par[y]=x;
		if(rank[x]==rank[y])rank[x]++;
	}
}

bool same(int x,int y){
	return find(x)==find(y);
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d",&p[i].first,&p[i].second);
		xi.push_back(p[i].first);
	}
	sort(xi.begin(),xi.end());
	xi.erase(unique(xi.begin(),xi.end()),xi.end());
	sort(p,p+n);
	for(int i=0;i<n;i++){
		p[i].first=lower_bound(xi.begin(),xi.end(),p[i].first)-xi.begin();
		query.push_back(P(p[i].second,p[i].first));
	}
	for(int i=0;i<(int)xi.size()-1;i++){
		edge.push_back(PP(xi[i+1]-xi[i],P(i,i+1)));
	}
	sort(query.begin(),query.end());
	for(int i=0;i<(int)query.size()-1;i++){
		int f=query[i+1].second;
		int t=query[i].second;
		int cost=query[i+1].first-query[i].first;
		edge.push_back(PP(cost,P(f,t)));
	}
	sort(edge.begin(),edge.end());
	init();
	ll res=0;
	for(int i=0;i<edge.size();i++){
		if(!same(edge[i].second.first,edge[i].second.second)){
			unite(edge[i].second.first,edge[i].second.second);
			res=(ll)res+edge[i].first;
		}
	}
	printf("%lld\n",res);
	return 0;
}


Compiler output:
a.cc: In function 'void init()':
a.cc:31:17: error: reference to 'rank' is ambiguous
   31 |                 rank[i]=0;
      |                 ^~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/vector:62,
                 from a.cc:3:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:25:5: note:                 'int rank [100001]'
   25 | int rank[100001];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:47:12: error: reference to 'rank' is ambiguous
   47 |         if(rank[x]<rank[y]){
      |            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:25:5: note:                 'int rank [100001]'
   25 | int rank[100001];
      |     ^~~~
a.cc:47:20: error: reference to 'rank' is ambiguous
   47 |         if(rank[x]<rank[y]){
      |                    ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:25:5: note:                 'int rank [100001]'
   25 | int rank[100001];
      |     ^~~~
a.cc:51:20: error: reference to 'rank' is ambiguous
   51 |                 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:25:5: note:                 'int rank [100001]'
   25 | int rank[100001];
      |     ^~~~
a.cc:51:29: error: reference to 'rank' is ambiguous
   51 |                 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:25:5: note:                 'int rank [100001]'
   25 | int rank[100001];
      |     ^~~~
a.cc:51:37: error: reference to 'rank' is ambiguous
   51 |                 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:25:5: note:                 'int rank [100001]'
   25 | int rank[100001];
      |     ^~~~