Language: C++

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct edge{
	int u;	//?????????
	int v;	//??°??????
	int cost;	//??????
	//???????????????????????§?????§?°???¢????????????
	bool operator<(const edge& another) const {
			return cost < another.cost;
	}
};

const int MAX_N = 100000;
const int MAX_M = 100000;

edge es[MAX_M];
int par[MAX_N];
int rank[MAX_N];

void initial(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???????????¨??¨y???????????¨?????????
	x = find(x);	//x???????????¨??????????????????x??¨??????
	y = find(y);	//y???????????¨??????????????????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(int x,int y){	//x,y???????????¨???????????§?????????
	return find(x) == find(y);
}

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

int kruskal(int n,int m){
	initial(n);
	int res = 0;
	for(int i=0;i<m;i++){
		edge e = es[i];
		if(!same(e.u,e.v)){
			unite(e.u,e.v);
			res += e.cost;
		}
	}
	return res;
}

int main(){
	int n,m,k,l;
	cin >> n;	//????????°?????\???
	cin >> m;	//?????°?????\???
	for(int i=0;i<m;i++){
		cin >> j >> k >> l;
		es[cnt].u = j;	es[cnt].v = k;	es[cnt].cost = l;
	}
	sort(es,es+m);
	cout << kruskal(n,m) << "\n";
}

Compiler output:
a.cc: In function 'void initial(int)':
a.cc:27:17: error: reference to 'rank' is ambiguous
   27 |                 rank[i] = 0;
      |                 ^~~~
In file included from /usr/include/c++/14/bits/move.h:37,
                 from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:22:5: note:                 'int rank [100000]'
   22 | int rank[MAX_N];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:43:12: error: reference to 'rank' is ambiguous
   43 |         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:22:5: note:                 'int rank [100000]'
   22 | int rank[MAX_N];
      |     ^~~~
a.cc:43:22: error: reference to 'rank' is ambiguous
   43 |         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:22:5: note:                 'int rank [100000]'
   22 | int rank[MAX_N];
      |     ^~~~
a.cc:47:20: error: reference to 'rank' is ambiguous
   47 |                 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:22:5: note:                 'int rank [100000]'
   22 | int rank[MAX_N];
      |     ^~~~
a.cc:47:31: error: reference to 'rank' is ambiguous
   47 |                 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:22:5: note:                 'int rank [100000]'
   22 | int rank[MAX_N];
      |     ^~~~
a.cc:48:25: error: reference to 'rank' is ambiguous
   48 |                         rank[x]++;
      |                         ^~~~
/usr/include/c++/14/type_traits:1437:12: note: candidates are: 'template<class> struct std::rank'
 1437 |     struct rank
      |            ^~~~
a.cc:22:5: note:                 'int rank [100000]'
   22 | int rank[MAX_N];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:78:24: error: 'j' was not declared in this scope
   78 |                 cin >> j >> k >> l;
      |                        ^
a.cc:79:20: error: 'cnt' was not declared in this scope; did you mean 'int'?
   79 |                 es[cnt].u = j;  es[cnt].v = k;  es[cnt].cost = l;
      |                    ^~~
      |                    int