Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#define int long long
#define ll long long
const int maxn=2e5+1000;
using namespace std;
int n,m,q,fa[maxn],check[maxn];
vector<pair<int,int> >one,zero;
pair<int,int>add;
int get(int x) {
    if(fa[x]==x)return x;
    fa[x]=get(fa[x]);
    return fa[x];
}
void uni(int u,int v){fa[get(u)]=get(v);}
signed main() {
    scanf("%lld%lld%lld",&n,&m,&q);
    for(int i=1;i<=n;i++)fa[i]=i;
    for(int i=1;i<=q;i++) {
        int u,v,c;scanf("%lld%lld%lld",&u,&v,&c);u++,v++;
        add.first=u,add.second=v;
        if(c==1) one.push_back(add);
        else zero.push_back(add);
    }
    for(int i=0;i<zero.size();i++) {
        if(get(zero[i].first)==get(zero[i].second)) {
            printf("No");return 0;
        }
        uni(zero[i].first,zero[i].second);
    }

    for(int i=0;i<one.size();i++) {
        if(get(one[i].first)==get(one[i].second)) {
            printf("No");return 0;
        }
    }

    int block=0;for(int i=1;i<=n;i++)if(!check[get(i)]){check[get(i)]=1;block++;}
    int p=m-(n-block);ll lim=(ll)block*(block-1);lim/=2;


   // cerr<<block<<' '<<p<<' '<<lim<<endl;
    if(one.size()==0&&block-1<=p&&p<=lim) {
        printf("Yes");return 0;
    }
    if(one.size()&&max(3,block)<=p&&p<=lim) {
        printf("Yes");return 0;
    }
    printf("No");return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:48:23: error: no matching function for call to 'max(int, long long int&)'
   48 |     if(one.size()&&max(3,block)<=p&&p<=lim) {
      |                    ~~~^~~~~~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:48:23: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   48 |     if(one.size()&&max(3,block)<=p&&p<=lim) {
      |                    ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303: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:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:48:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   48 |     if(one.size()&&max(3,block)<=p&&p<=lim) {
      |                    ~~~^~~~~~~~~