Language: C++

#include<algorithm>
#include<vector>

using namespace std;

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

int par[101],rank[101];
edge es[200];
int V,E;

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

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

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

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

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

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(e.u,e.v))unite(e.u,e.v),res+=e.cost;
  }
  return res;
}

int main(void){
  int a,b,c;

  while(cin >> V >> E && V){
    for(int i=0;i<E;i++){
      cin >> a >> b >> c;
      es[i].u=a,es[i].v=b,es[i].cost=c;
    }
    cout << kruskal() << endl;
  }
  return 0;
}

Compiler output:
a.cc: In function 'void init_union_find(int)':
a.cc:12:58: error: reference to 'rank' is ambiguous
   12 | void init_union_find(int n){for(int i=0;i<n;i++)par[i]=i,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:8:14: note:                 'int rank [101]'
    8 | int par[101],rank[101];
      |              ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:22:6: error: reference to 'rank' is ambiguous
   22 |   if(rank[x] < rank[y])par[x]=y;
      |      ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:14: note:                 'int rank [101]'
    8 | int par[101],rank[101];
      |              ^~~~
a.cc:22:16: error: reference to 'rank' is ambiguous
   22 |   if(rank[x] < rank[y])par[x]=y;
      |                ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:8:14: note:                 'int rank [101]'
    8 | int par[101],rank[101];
      |              ^~~~
a.cc:23:17: error: reference to 'rank' is ambiguous
   23 |   else par[y]=x,rank[x]+=(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:8:14: note:                 'int rank [101]'
    8 | int par[101],rank[101];
      |              ^~~~
a.cc:23:27: error: reference to 'rank' is ambiguous
   23 |   else par[y]=x,rank[x]+=(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:8:14: note:                 'int rank [101]'
    8 | int par[101],rank[101];
      |              ^~~~
a.cc:23:36: error: reference to 'rank' is ambiguous
   23 |   else par[y]=x,rank[x]+=(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:8:14: note:                 'int rank [101]'
    8 | int par[101],rank[101];
      |              ^~~~
a.cc: In function 'int main()':
a.cc:44:9: error: 'cin' was not declared in this scope
   44 |   while(cin >> V >> E && V){
      |         ^~~
a.cc:3:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    2 | #include<vector>
  +++ |+#include <iostream>
    3 | 
a.cc:49:5: error: 'cout' was not declared in this scope
   49 |     cout << kruskal() << endl;
      |     ^~~~
a.cc:49:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:49:26: error: 'endl' was not declared in this scope
   49 |     cout << kruskal() << endl;
      |                          ^~~~
a.cc:3:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    2 | #include<vector>
  +++ |+#include <ostream>
    3 |