Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <map>
#include <bitset>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

const ll SZ = 3e5 + 10, INF = 1e9 + 100, MOD = 1e9 + 7;

ll n, m, q;

ll ans = 0;

vector<tuple<ll, ll, ll>> vec;

ll dsu[SZ], kek[SZ];

ll find(int v) {
	if (dsu[v] == v) return v;
	return dsu[v] = find(dsu[v]);
}

void uni(int v, int u) {
	v = find(v);
	u = find(u);
	if (u != v) {
		dsu[u] = v;
		ans++;
	}
}

void mrk(int v) {
	v = find(v);
	kek[v] = 1;
}

int main() {
	fastInp;

	cin >> n >> m >> q;

	for (int i = 0; i < n; i++) dsu[i] = i;
	while (q--) {
		ll u, v, t;
		cin >> u >> v >> t;
		vec.push_back({ u, v, t });
	}

	for (int i = 0; i < vec.size(); i++) {
		if (get<2>(vec[i]) == 0) {
			uni(get<0>(vec[i]), get<1>(vec[i]));
		}
	}

	for (int i = 0; i < vec.size(); i++) {
		if (get<2>(vec[i]) == 1) {
			mrk(get<0>(vec[i]));
			mrk(get<1>(vec[i]));
			if (find(get<0>(vec[i])) == find(get<1>(vec[i]))) {
				cout << "No";
				return 0;
			}
		}
	}

	ll cnt = 0, mn = 0;
	set<ll> s, s2;
	for (int i = 0; i < n; i++) {
		s.insert(find(i));
		if (kek[i]) s2.insert(find(i));
	}

	if (s.size() == 1) {
		cout << "No";
		return 0;
	}

	if (s.size() == 2) {
		cout << "No";
		return 0;
	}

	if (m < (min(s2.size(), 3u) + 1 + ans)) {
		cout << "No";
		return 0;
	}

	ll k = s.size();
	if (m > (k * (k - 1)) / 2 + ans) {
		cout << "No";
		return 0;
	}

	cout << "Yes";

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:92:21: error: no matching function for call to 'min(std::set<long long int>::size_type, unsigned int)'
   92 |         if (m < (min(s2.size(), 3u) + 1 + ans)) {
      |                  ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:92:21: note:   deduced conflicting types for parameter 'const _Tp' ('long unsigned int' and 'unsigned int')
   92 |         if (m < (min(s2.size(), 3u) + 1 + ans)) {
      |                  ~~~^~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:92:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'long unsigned int'
   92 |         if (m < (min(s2.size(), 3u) + 1 + ans)) {
      |                  ~~~^~~~~~~~~~~~~~~