Language: C++

#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;

struct edge{ int u, v; ll cost; };

bool cmp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

int par[100000], rank[100000];

int find(int x){
	if(par[x] == x) return x;
	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 n;
P xs[100000], ys[100000];
edge es[200000];

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		ll x, y; scanf("%lld %lld", &x, &y);
		xs[i] = P(x, i); ys[i] = P(y, i);
		par[i] = i;
	}
	sort(xs, xs + n); sort(ys, ys + n);
	for(int i = 0; i < n - 1; i++){
		es[2 * i] = (edge){xs[i].second, xs[i + 1].second, xs[i + 1].first - xs[i].first};
		es[2 * i + 1] = (edge){ys[i].second, ys[i + 1].second, ys[i + 1].first - ys[i].first};
	}
	sort(es, es + 2 * (n - 1), cmp);
	ll res = 0;
	for(int i = 0; i < 2 * (n - 1); i++){
		if(!same(es[i].u, es[i].v)){
			unite(es[i].u, es[i].v);
			res += es[i].cost;
		}
	}
	printf("%lld\n", res);
	return 0;
}

Compiler output:
a.cc: In function 'void unite(int, int)':
a.cc:25:12: error: reference to 'rank' is ambiguous
   25 |         if(rank[x] < rank[y]) par[x] = y;
      |            ^~~~
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/algorithm:60,
                 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:15:18: note:                 'int rank [100000]'
   15 | int par[100000], rank[100000];
      |                  ^~~~
a.cc:25:22: error: reference to 'rank' is ambiguous
   25 |         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:15:18: note:                 'int rank [100000]'
   15 | int par[100000], rank[100000];
      |                  ^~~~
a.cc:28:20: error: reference to 'rank' is ambiguous
   28 |                 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:15:18: note:                 'int rank [100000]'
   15 | int par[100000], rank[100000];
      |                  ^~~~
a.cc:28:31: error: reference to 'rank' is ambiguous
   28 |                 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:15:18: note:                 'int rank [100000]'
   15 | int par[100000], rank[100000];
      |                  ^~~~
a.cc:28:40: error: reference to 'rank' is ambiguous
   28 |                 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:15:18: note:                 'int rank [100000]'
   15 | int par[100000], rank[100000];
      |                  ^~~~