Language: C++

#include <bits/stdc++.h>


using namespace std;
typedef pair<int,int> P;
int n;
P x[100001];
P y[100001];
int p[100001];
int rank[100001];

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

int Find(int x) {
  return p[x] == x ? x : (p[x] = Find(p[x]));
}

void Union(int x, int y) {
  int a = Find(x);
  int b = Find(y);
  if(a == b) return;
  if(rank[x] > rank[y])  p[y] = x;
  else {
    p[x] = y;
    if(rank[x] == rank[y]) rank[x]++;
  }
}
    
				 
			  
struct edge{
  int cost,from,to;

  edge(int c, int f, int t) : cost(c),from(f),to(t) {}
    
};

bool operator < (const edge& x, const edge& y) {
    return x.cost < y.cost;
  }

vector<edge> e;
int main() {
  cin >> n;
  init(n);
  for(int i = 0; i < n; i++) {
    int xx, yy;
    cin >> xx >> yy;
    x[i] = P(xx,i);
    y[i] = P(yy,i);
  }
  sort(x,x+n);
  sort(y,y+n);
  for(int i = 1; i < n; i++) {
    e.push_back(edge(abs(x[i].first - x[i-1].first),x[i-1].second,x[i].second));
    e.push_back(edge(abs(x[i].first - x[i-1].first),x[i].second,x[i-1].second));    e.push_back(edge(abs(y[i].first - y[i-1].first),y[i-1].second,y[i].second));
    e.push_back(edge(abs(y[i].first - y[i-1].first),y[i].second,y[i-1].second));
  }

  sort(e.begin(),e.end());
      

  /*for(int i = 0; i < e.size();i++) {
    cout << e[i].cost <<"   "<<e[i].from<<"   "<<e[i].to<<endl;
    }*/
  long long int ans = 0;

  for(int i = 0; i < e.size(); i++) {
    if(Find(e[i].from) != Find(e[i].to)) {
      //cout << Find(e[i].from) <<"   "<<Find(e[i].to)<<endl;
      // cout << e[i].cost <<"   "<<e[i].from<<"   "<<e[i].to<< endl;
      ans += e[i].cost;
      //cout << ans << endl;
      Union(Find(e[i].from),Find(e[i].to));
    }
  }

  cout << ans << endl;
  
}

  
    
  


Compiler output:
a.cc: In function 'void init(int)':
a.cc:15:5: error: reference to 'rank' is ambiguous
   15 |     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/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 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:10:5: note:                 'int rank [100001]'
   10 | int rank[100001];
      |     ^~~~
a.cc: In function 'void Union(int, int)':
a.cc:27:6: error: reference to 'rank' is ambiguous
   27 |   if(rank[x] > rank[y])  p[y] = x;
      |      ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:10:5: note:                 'int rank [100001]'
   10 | int rank[100001];
      |     ^~~~
a.cc:27:16: error: reference to 'rank' is ambiguous
   27 |   if(rank[x] > rank[y])  p[y] = x;
      |                ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:10:5: note:                 'int rank [100001]'
   10 | int rank[100001];
      |     ^~~~
a.cc:30:8: error: reference to 'rank' is ambiguous
   30 |     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:10:5: note:                 'int rank [100001]'
   10 | int rank[100001];
      |     ^~~~
a.cc:30:19: error: reference to 'rank' is ambiguous
   30 |     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:10:5: note:                 'int rank [100001]'
   10 | int rank[100001];
      |     ^~~~
a.cc:30:28: error: reference to 'rank' is ambiguous
   30 |     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:10:5: note:                 'int rank [100001]'
   10 | int rank[100001];
      |     ^~~~