Language: C++

#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
typedef long long ll;

int par[100000];
int rank[100000];
int n;

void init(int k){
	for(int i = 0; i < k; ++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(){
	int n; cin >> n;
	init(n);
	vector< pair<int, int> > vx, vy;
	for(int i = 0; i < n; ++i){
		int x, y; cin >> x >> y; --x; --y;
		vx.push_back(pair<int, int>(x, i));
		vy.push_back(pair<int, int>(y, i));
	}
	sort(vx.begin(), vx.end());
	sort(vy.begin(), vy.end());
	vector< pair<int, pair<int, int> > > v;
	for(int i = 0; i < n - 1; ++i){
		pair< int, pair<int, int> > p;
		p.first = vx[i + 1].first - vx[i].first;
		p.second = pair<int, int>(vx[i + 1].second, vx[i].second);
		v.push_back(p);
		p.first = vy[i + 1].first - vy[i].first;
		p.second = pair<int, int>(vy[i + 1].second, vy[i].second);
		v.push_back(p);
	}
	sort(v.begin(), v.end());
	int ans = 0;
	for(int i = 0; i < v.size(); ++i){
		if(!same(v[i].second.first, v[i].second.second)){
			unite(v[i].second.first, v[i].second.second);
			ans += v[i].first;
		}
	}
	cout << ans << endl;
	return 0;
}

Compiler output:
a.cc: In function 'void init(int)':
a.cc:15:17: error: reference to 'rank' is ambiguous
   15 |                 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:1:
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:9:5: note:                 'int rank [100000]'
    9 | int rank[100000];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:32:12: error: reference to 'rank' is ambiguous
   32 |         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:9:5: note:                 'int rank [100000]'
    9 | int rank[100000];
      |     ^~~~
a.cc:32:22: error: reference to 'rank' is ambiguous
   32 |         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:9:5: note:                 'int rank [100000]'
    9 | int rank[100000];
      |     ^~~~
a.cc:36:20: error: reference to 'rank' is ambiguous
   36 |                 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:9:5: note:                 'int rank [100000]'
    9 | int rank[100000];
      |     ^~~~
a.cc:36:31: error: reference to 'rank' is ambiguous
   36 |                 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:9:5: note:                 'int rank [100000]'
    9 | int rank[100000];
      |     ^~~~
a.cc:36:42: error: reference to 'rank' is ambiguous
   36 |                 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:9:5: note:                 'int rank [100000]'
    9 | int rank[100000];
      |     ^~~~