Language: C++

#include <algorithm>
#include <cstdio>
#define MAX_E 100000

using namespace std;

struct edge {
    int u, v, cost;
    edge() {}
    edge(int a, int b, int c) : u(a), v(b), cost(c) {}
};

int n, m;
int par[MAX_E];
int rank[MAX_E];
edge edges[MAX_E];

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

// Ant book p84. union-find tree
void uf_init(int n) {
    for (int i = 0; i < n; i++) {
        par[i] = i;
        rank[i] = 0;
    }
}

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

void uf_unite(int x, int y) {
    x = uf_find(x);
    y = uf_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 uf_same(int x, int y) {
    return uf_find(x) == uf_find(y);
}

// Ant book p101. kruskal
int kruskal() {
    sort(edges, edges + m, comp);
    uf_init(n);
    int res = 0;
    for (int i = 0; i < m; i++) {
        edge e = edges[i];
        if (!uf_same(e.u, e.v)) {
            uf_unite(e.u, e.v);
            res += e.cost;
        }
    }
    return res;
}

int main() {
    int x, y, w;

    scanf("%d %d", &n, &m);
    for (int j = 0; j < m; j++) {
        scanf("%d %d %d", &x, &y, &w);
        edges[j] = edge(x, y, w);
    }
    printf("%d\n", kruskal());
}

    return 0;
}

Compiler output:
a.cc: In function 'void uf_init(int)':
a.cc:26:9: error: reference to 'rank' is ambiguous
   26 |         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:15:5: note:                 'int rank [100000]'
   15 | int rank[MAX_E];
      |     ^~~~
a.cc: In function 'void uf_unite(int, int)':
a.cc:44:9: error: reference to 'rank' is ambiguous
   44 |     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:15:5: note:                 'int rank [100000]'
   15 | int rank[MAX_E];
      |     ^~~~
a.cc:44:19: error: reference to 'rank' is ambiguous
   44 |     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:15:5: note:                 'int rank [100000]'
   15 | int rank[MAX_E];
      |     ^~~~
a.cc:49:13: error: reference to 'rank' is ambiguous
   49 |         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:15:5: note:                 'int rank [100000]'
   15 | int rank[MAX_E];
      |     ^~~~
a.cc:49:24: error: reference to 'rank' is ambiguous
   49 |         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:15:5: note:                 'int rank [100000]'
   15 | int rank[MAX_E];
      |     ^~~~
a.cc:49:33: error: reference to 'rank' is ambiguous
   49 |         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:15:5: note:                 'int rank [100000]'
   15 | int rank[MAX_E];
      |     ^~~~
a.cc: At global scope:
a.cc:83:5: error: expected unqualified-id before 'return'
   83 |     return 0;
      |     ^~~~~~
a.cc:84:1: error: expected declaration before '}' token
   84 | }
      | ^