Language: C++

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <utility>
using namespace std;

#define MAX_N 100000+10
#define MAX_E 4*(100000+10)
int par[MAX_N];
int rank[MAX_N];

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

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

void unite_union_find(int x, int y) {
  x = find_union_find(x);
  y = find_union_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_union_find(int x, int y) {
  return find_union_find(x) == find_union_find(y);
}

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

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


edge es[MAX_E];
int V,E;

int kruskal() {
  sort(es, es+E, comp);
  init_union_find(V);
  int res=0;
  for(int i=0;i<E;++i) {
    edge e =es[i];
    if(!same_union_find(e.u,e.v)){
      unite_union_find(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}


typedef pair<int,int> city_data;

city_data x[MAX_N];
city_data y[MAX_N];

int main() {
  int N;
  scanf("%d", &N);
  for(int i=0;i<N;++i){
    scanf("%d%d", &x[i].first, &y[i].first);
    x[i].second = i;
    y[i].second = i;
  }

  V=N;

  sort(x, x+N);
  sort(y, y+N);

  int it=0;
  for(int i=0;i<N-1;++i){
    {
      int cost=abs(x[i].first - x[i+1].first);
      es[it].u=x[i].second;
      es[it].v=x[i+1].second;
      es[it].cost=cost;
      it++;
    }
    {
      int cost=abs(y[i].first - y[i+1].first);
      es[it].u=y[i].second;
      es[it].v=y[i+1].second;
      es[it].cost=cost;
      it++;
    }
  }
  E=it;


  printf("%d",kruskal());
 
  
  return 0;
}

Compiler output:
a.cc: In function 'void init_union_find(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 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 [100010]'
   10 | int rank[MAX_N];
      |     ^~~~
a.cc: In function 'void unite_union_find(int, int)':
a.cc:32:7: 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:10:5: note:                 'int rank [100010]'
   10 | int rank[MAX_N];
      |     ^~~~
a.cc:32:17: 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:10:5: note:                 'int rank [100010]'
   10 | int rank[MAX_N];
      |     ^~~~
a.cc:36:9: error: reference to 'rank' is ambiguous
   36 |     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:10:5: note:                 'int rank [100010]'
   10 | int rank[MAX_N];
      |     ^~~~
a.cc:36:20: error: reference to 'rank' is ambiguous
   36 |     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:10:5: note:                 'int rank [100010]'
   10 | int rank[MAX_N];
      |     ^~~~
a.cc:37:7: error: reference to 'rank' is ambiguous
   37 |       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 [100010]'
   10 | int rank[MAX_N];
      |     ^~~~