Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;
int par[100010];
int rank[100010];

void init(int n)
{
    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);
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    init(n);
    vector<pair<int, int> > y(n);
    vector<pair<int, int> > x(n);
    for(int i = 1; i <= n; i++){
        cin >> x[i - 1].first;
        cin >> y[i - 1].first;
        x[i - 1].second = i;
        y[i - 1].second = i;
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    vector<pair<int, pair<int, int> > > distance;
    for(int i = 0; i < n - 1; i++){
        pair<int, pair<int, int> > in;
        in.second.first = x[i].second;
        in.second.second = x[i + 1].second;
        in.first = x[i + 1].first - x[i].first;
        distance.push_back(in);
        in.second.first = y[i].second;
        in.second.second = y[i + 1].second;
        in.first = y[i + 1].first - y[i].first;
        distance.push_back(in);
    }
    long long ans = 0;
    sort(distance.begin(), distance.end());
    for(int i = 1; i < n; i++){
        while(same(distance[0].second.first, distance[0].second.second)){
            distance.erase(distance.begin(), distance.begin() + 1);
        }
        ans += (long long)distance[0].first;
        unite(distance[0].second.first, distance[0].second.second);
        distance.erase(distance.begin(), distance.begin() + 1);
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'void init(int)':
a.cc:25:9: error: reference to 'rank' is ambiguous
   25 |         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:19:5: note:                 'int rank [100010]'
   19 | int rank[100010];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:45:8: error: reference to 'rank' is ambiguous
   45 |     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:19:5: note:                 'int rank [100010]'
   19 | int rank[100010];
      |     ^~~~
a.cc:45:18: error: reference to 'rank' is ambiguous
   45 |     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:19:5: note:                 'int rank [100010]'
   19 | int rank[100010];
      |     ^~~~
a.cc:49:12: error: reference to 'rank' is ambiguous
   49 |         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:19:5: note:                 'int rank [100010]'
   19 | int rank[100010];
      |     ^~~~
a.cc:49:23: error: reference to 'rank' is ambiguous
   49 |         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:19:5: note:                 'int rank [100010]'
   19 | int rank[100010];
      |     ^~~~
a.cc:50:13: error: reference to 'rank' is ambiguous
   50 |             rank[x]++;
      |             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:19:5: note:                 'int rank [100010]'
   19 | int rank[100010];
      |     ^~~~