Language: C++

#include <bits/stdc++.h>
using namespace std;

typedef long long int LLI;
typedef pair<int, int> Pair;
typedef pair<int, Pair> Edge;

int N;
LLI ans;
int par[114514];
int rank[114514];
vector<Pair> xs;
vector<Pair> ys;
vector<Edge> es;

int find(int v) {
  if (par[v] == v) return v;
  return par[v] = find(par[v]);
}

int same(int u, int v) {
  return find(u) == find(v);
}

void unite(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return;
  if (rank[u] > rank[v]) par[v] = u;
  else {
    par[u] = v;
    if (rank[u] == rank[v]) rank[v]++;
  }
}

int main() {
  scanf("%d", &N);
  for (int i=0; i<N; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    xs.emplace_back(Pair(x, i));
    ys.emplace_back(Pair(y, i));
    par[i] = i;
  }
  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  for (int i=1; i<N; i++) {
    es.emplace_back(Edge(xs[i].first-xs[i-1].first, 
         Pair(xs[i-1].second, xs[i].second)));
    es.emplace_back(Edge(ys[i].first-ys[i-1].first, 
         Pair(ys[i-1].second, ys[i].second)));
  }
  sort(es.begin(), es.end());
  for (auto &e : es) {
    int u, v;
    tie(u, v) = e.second;
    if (same(u, v)) continue;
    unite(u, v);
    ans += e.first;
  }
  printf("%lld\n", ans);
}
    
  

Compiler output:
a.cc: In function 'void unite(int, int)':
a.cc:29:7: error: reference to 'rank' is ambiguous
   29 |   if (rank[u] > rank[v]) par[v] = u;
      |       ^~~~
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:11:5: note:                 'int rank [114514]'
   11 | int rank[114514];
      |     ^~~~
a.cc:29:17: error: reference to 'rank' is ambiguous
   29 |   if (rank[u] > rank[v]) par[v] = u;
      |                 ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:11:5: note:                 'int rank [114514]'
   11 | int rank[114514];
      |     ^~~~
a.cc:32:9: error: reference to 'rank' is ambiguous
   32 |     if (rank[u] == rank[v]) rank[v]++;
      |         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:11:5: note:                 'int rank [114514]'
   11 | int rank[114514];
      |     ^~~~
a.cc:32:20: error: reference to 'rank' is ambiguous
   32 |     if (rank[u] == rank[v]) rank[v]++;
      |                    ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:11:5: note:                 'int rank [114514]'
   11 | int rank[114514];
      |     ^~~~
a.cc:32:29: error: reference to 'rank' is ambiguous
   32 |     if (rank[u] == rank[v]) rank[v]++;
      |                             ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:11:5: note:                 'int rank [114514]'
   11 | int rank[114514];
      |     ^~~~