Language: C++

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

struct UnionFind {
	UnionFind(int n = 0): par(n, -1){}
	int root(int x){
		return par[x] < 0 ? x : par[x] = root(par[x]);
	}
	bool unite(int x, int y){
		if ((x = root(x)) == (y = find(y))) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}
};

int n, m;
vector<tuple<int, int, int, int> > v;

int main()
{
	while (cin >> n >> m, n){
		v.clear();
		for (int i = 0; i < m; i++){
			int u, v, d, c;
			cin >> u >> v >> d >> c;
			v.emplace_back(d, c, --u, --v);
		}
		sort(begin(v), end(v));
		UnionFind uf(n);
		int res = 0;
		for (int i = 0; i < m; i++){
			int d, c, u, v;
			tie(d, c, u, v) = v[i];
			if (uf.unite(u, v)){
				res += c;
			}
		}
		cout << res << endl;
	}
}

Compiler output:
a.cc: In constructor 'UnionFind::UnionFind(int)':
a.cc:5:31: error: class 'UnionFind' does not have any field named 'par'
    5 |         UnionFind(int n = 0): par(n, -1){}
      |                               ^~~
a.cc: In member function 'int UnionFind::root(int)':
a.cc:7:24: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
    7 |                 return par[x] < 0 ? x : par[x] = root(par[x]);
      |                        ^~~
      |                        __pstl::execution::v1::par
In file included from /usr/include/c++/14/pstl/glue_algorithm_defs.h:15,
                 from /usr/include/c++/14/algorithm:86,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc: In member function 'bool UnionFind::unite(int, int)':
a.cc:10:47: error: no matching function for call to 'find(int&)'
   10 |                 if ((x = root(x)) == (y = find(y))) return false;
      |                                           ~~~~^~~
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:3842:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
 3842 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
   60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note:   candidate expects 4 arguments, 1 provided
In file included from /usr/include/c++/14/iterator:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
  435 |     find(istreambuf_iterator<_CharT> __first,
      |     ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note:   candidate expects 3 arguments, 1 provided
a.cc:11:21: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   11 |                 if (par[x] > par[y]) swap(x, y);
      |                     ^~~
      |                     __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc:12:17: error: 'par' was not declared in this scope; did you mean '__pstl::execution::v1::par'?
   12 |                 par[x] += par[y];
      |                 ^~~
      |                 __pstl::execution::v1::par
/usr/include/c++/14/pstl/execution_defs.h:43:45: note: '__pstl::execution::v1::par' declared here
   43 | _GLIBCXX17_INLINE constexpr parallel_policy par{};
      |                                             ^~~
a.cc: In function 'int main()':
a.cc:28:27: error: request for member 'emplace_back' in 'v', which is of non-class type 'int'
   28 |                         v.emplace_back(d, c, --u, --v);
      |                           ^~~~~~~~~~~~
a.cc:35:44: error: invalid types 'int[int]' for array subscript
   35 |                         tie(d, c, u, v) = v[i];
      |                                            ^