Language: C++

#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>

#define PI 3.14159265359

#define INF 99999999;

#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)

typedef long long ll;

using namespace std;



/*
class LightSwitchingPuzzle
{
public:
	int minFlips(string s)
	{

	}
}
*/


int rank[100000];
int par[10000];

void init(int n)
{
	REP(n)
	{
		rank[i] = 0;
		par[i] = i;
	}
}

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;
		if (rank[x] == rank[y]) rank[x]++;
	}
}

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

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

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

edge es[100000];

int main()
{
	int V, E;
	
	cin >> V >> E;
	REP(E)
	{
		cin >> es[i].u >> es[i].v >> es[i].cost;
	}
	
	sort(es, es + E, comp);
	init(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;
		}
	}
	
	cout << res << endl;
	
	return 0;
}

Compiler output:
a.cc: In function 'void init(int)':
a.cc:45:17: error: reference to 'rank' is ambiguous
   45 |                 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:38:5: note:                 'int rank [100000]'
   38 | int rank[100000];
      |     ^~~~
a.cc: In function 'void unite(int, int)':
a.cc:62:13: error: reference to 'rank' is ambiguous
   62 |         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:38:5: note:                 'int rank [100000]'
   38 | int rank[100000];
      |     ^~~~
a.cc:62:23: error: reference to 'rank' is ambiguous
   62 |         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:38:5: note:                 'int rank [100000]'
   38 | int rank[100000];
      |     ^~~~
a.cc:67:21: error: reference to 'rank' is ambiguous
   67 |                 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:38:5: note:                 'int rank [100000]'
   38 | int rank[100000];
      |     ^~~~
a.cc:67:32: error: reference to 'rank' is ambiguous
   67 |                 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:38:5: note:                 'int rank [100000]'
   38 | int rank[100000];
      |     ^~~~
a.cc:67:41: error: reference to 'rank' is ambiguous
   67 |                 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:38:5: note:                 'int rank [100000]'
   38 | int rank[100000];
      |     ^~~~