Language: C++

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

#define MAX_N 100010

struct point {int id, x, y;};
struct edge {int u, v, w;};

int n;
point p[MAX_N];
edge edgeset[2 * MAX_N];

int pa[MAX_N];
int rank[MAX_N];

void init(void)
{
    memset(pa, 0, sizeof(pa));
    memset(rank, 0, sizeof(rank));
    for (int i = 0; i < n; i++) {
        pa[i] = i;
        rank[i] = 0;
    }
}

int find(int x)
{
    if (pa[x] == x) return x;
    else return pa[x] = find(pa[x]);
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) pa[x] = y;
    else {
        pa[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
}

bool same(int x, int y)
{
    return (find(x) == find(y));
}

int abs(int a)
{
    return a >= 0? a: -a;
}

bool cmp_x(point a, point b)
{
    return a.x < b.x;
}

bool cmp_y(point a, point b)
{
    return a.y < b.y;
}

bool cmp_edge(edge a, edge b)
{
    return a.w <= b.w;
}

int mst(void)
{
    init();
    int res = 0;
    for (int i = 0; i < 2 * (n - 1); i++) {
        edge e = edgeset[i];
        if (!same(e.u, e.v)) {
            unite(e.u ,e.v);
            res += e.w;
        }
    }
    return res;
}

int main(void)
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d%d", &p[i].x, &p[i].y);
        p[i].id = i + 1;
    }
    sort(p, p + n, cmp_x);
    for (int i = 0; i < n - 1; i++) {
        edgeset[i].u = p[i].id;
        edgeset[i].v = p[i + 1].id;
        edgeset[i].w = abs(p[i + 1].x - p[i].x);
    }
    sort(p, p + n, cmp_y);
    for (int i = 0; i < n - 1; i++) {
        edgeset[i + n - 1].u = p[i].id;
        edgeset[i + n - 1].v = p[i + 1].id;
        edgeset[i + n - 1].w = abs(p[i + 1].y - p[i].y);
    }
    sort(edgeset, edgeset + 2 * (n - 1), cmp_edge);
    printf("%d\n", mst());
    return 0;
}


Compiler output:
a.cc: In function 'void init()':
a.cc:19:12: error: reference to 'rank' is ambiguous
   19 |     memset(rank, 0, sizeof(rank));
      |            ^~~~
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:14:5: note:                 'int rank [100010]'
   14 | int rank[MAX_N];
      |     ^~~~
a.cc:19:28: error: reference to 'rank' is ambiguous
   19 |     memset(rank, 0, sizeof(rank));
      |                            ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:14:5: note:                 'int rank [100010]'
   14 | int rank[MAX_N];
      |     ^~~~
a.cc:22:9: error: reference to 'rank' is ambiguous
   22 |         rank[i] = 0;
      |         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:14:5: note:                 'int rank [100010]'
   14 | int rank[MAX_N];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:37:9: error: reference to 'rank' is ambiguous
   37 |     if (rank[x] < rank[y]) pa[x] = y;
      |         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:14:5: note:                 'int rank [100010]'
   14 | int rank[MAX_N];
      |     ^~~~
a.cc:37:19: error: reference to 'rank' is ambiguous
   37 |     if (rank[x] < rank[y]) pa[x] = y;
      |                   ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:14:5: note:                 'int rank [100010]'
   14 | int rank[MAX_N];
      |     ^~~~
a.cc:40:13: error: reference to 'rank' is ambiguous
   40 |         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:14:5: note:                 'int rank [100010]'
   14 | int rank[MAX_N];
      |     ^~~~
a.cc:40:24: error: reference to 'rank' is ambiguous
   40 |         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:14:5: note:                 'int rank [100010]'
   14 | int rank[MAX_N];
      |     ^~~~
a.cc:40:33: error: reference to 'rank' is ambiguous
   40 |         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:14:5: note:                 'int rank [100010]'
   14 | int rank[MAX_N];
      |     ^~~~