criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,q,tot,cnt,sum[N],f[N],head[N],nex[N<<1],to[N<<1];
void add(int u,int v){to[++tot]=v;nex[tot]=head[u];head[u]=tot;}
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
vector<pair<int,int> >vc[2];
bool flag=true,vis[N];
ll m,res;
void dfs(int u,int p)
{
    vis[u]=true;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];if(v==p) continue;
        if(vis[v]) {flag=false;break;}
        m--;
        dfs(v,u);
    }
}
int s;
void dfs(int u)
{
    vis[u]=true;if(sum[u]==2) s++;
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];if(vis[v]) continue;
        dfs(v);
    }
}
int main()
{
    scanf("%d%lld%d",&n,&m,&q);
    for(int i=1;i<=n;i++) f[i]=i;
    for(int i=1;i<=q;i++)
    {
        int u,v,c;scanf("%d%d%d",&u,&v,&c);
        u++;v++;
        vis[u]=vis[v]=true;
        if(u>v) swap(u,v);
        vc[c].push_back({u,v});
    }
    for(int i=1;i<=n;i++) if(!vis[i]) cnt++;
    memset(vis,false,sizeof(vis));
    for(int i=0;i<vc[1].size();i++)
        f[getf(vc[1][i].fi)]=getf(vc[1][i].se);
    sort(vc[0].begin(),vc[0].end());
    for(int i=0;i<vc[0].size();i++)
        if(getf(vc[0][i].fi)==getf(vc[0][i].se)||i&&vc[i]==vc[i-1])
    {
        printf("No\n");return 0;
    }
    for(int i=0;i<vc[0].size();i++)
    {
        int u=getf(vc[0][i].fi),v=getf(vc[0][i].se);
        add(u,v);add(v,u);
    }
    for(int i=1;i<=n;i++)
        if(f[i]==i&&!vis[i])
        dfs(i,0);
    if(!flag||m<0){printf("No\n");return 0;}
    for(int i=1;i<=n;i++)
        sum[getf(i)]++;
    memset(vis,false,sizeof(vis));
    vector<int>v;
    for(int i=1;i<=n;i++)
        if(f[i]==i&&!vis[i])
        s=0,dfs(i),v.push_back(s);
    sort(v.begin(),v.end());
    s=0;
    for(int i=0;i<v.size()-1;i++)
        s+=v[i];
    int tot=0;
    for(int i=0;i<v.size();i++) if(v[i]==0) cnt++;
    if(s>=v.back()) m-=(s+v.back()>>1)*4,s=(s+back())%2;
    else m-=v.back()*4,s=v.back()-s;
    cnt-=s;
    m-=s*3;
    if(m>=0&&cnt>=0) printf("Yes\n");
    else printf("No\n");
}


Compiler output:
a.cc: In function 'int main()':
a.cc:78:47: error: 'back' was not declared in this scope
   78 |     if(s>=v.back()) m-=(s+v.back()>>1)*4,s=(s+back())%2;
      |                                               ^~~~
Language: C++

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int p[100010];
int root(int x){
	if(x == p[x]) return x;
	return p[x] = root(p[x]);
}
bool merge(int a, int b){
	a = root(a); b = root(b);
	if(a == b) return 0;
	p[b] = a;
	return 1;
}
void check(bool cond){
	cout << (cond ? "Yes" : "No") << endl;
	exit(0);
}

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n, m, q; cin >> n >> m >> q;
	int k = n;
	rep(i, n) p[i] = i;
	vector<pi> c1;
	rep(i, q){
		int a, b, c; cin >> a >> b >> c;
		if(c) c1.emplace_back(a, b);
		else{
			if(merge(a, b)) k--;
			s0.insert(a);
			s0.insert(b);
		}
	}
	for(pi i : c1){
		int a = root(i.first), b = root(i.second);
		if(a == b) check(0);
	}
	
	ll lim = k * (k - 1ll) / 2 + n - k;
	if(!c1.size()) check(m <= lim);
	check(n <= m && m <= lim && k >= 3);
	
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:43:25: error: 's0' was not declared in this scope; did you mean 'y0'?
   43 |                         s0.insert(a);
      |                         ^~
      |                         y0
Language: C++

#include <bits/stdc++.h>

#define int long long

#define pii pair<int, int>

#define x1 x1228
#define y1 y1228

#define left left228
#define right right228

#define pb push_back
#define eb emplace_back

#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   

#define matr vector<vector<int> > 

#define all(x) x.begin(), x.end()


using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 3e5 + 7, mod = 998244353, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll inf = 1e18;
mt19937 rnd(time(0));
int n, m, q; 
struct edge {
    int a, b, c; 
};

vector<edge> e;
int pr[maxn];
int siz[maxn];

int get(int a) {
    if (pr[a] == a) return a; 
    return pr[a] = get(pr[a]); 
} 

int ctr; 
bool unite(int a, int b) {
    a = get(a); 
    b = get(b); 
    if (a == b) return 0;
    if (siz[a] > siz[b]) swap(a, b);
    pr[a] = b;
    siz[b] += siz[a];
    return 1;  
}
  
void solve() {        
    cin >> n >> m >> q;
    ctr = n;  
    for (int i = 0; i < n; ++i) {
        pr[i] = i; 
        siz[i] = 1; 
    }
    set<pair<pii, int> > kek;
    for (int i = 0; i < q; ++i) {
        int a, b, c; cin >> a >> b >> c; 
        if (a > b) swap(a, b); 
        kek.insert(mp(mp(a, b), c)); 
    }
    for (auto v : kek) {
        e.pb({v.ff.ff, v.ff.ss, v.ss}); 
    }
    for (auto v : e) {
        if (v.c == 0) {
            int t = unite(v.a, v.b); 
            ctr -= t; 
        }
    } 
    set<pii> ms; 
    int ptr = 0; 
    for (auto v : e) {
        if (v.c == 1) {
            ptr++; 
            int a = get(v.a); 
            int b = get(v.b); 
            if (a == b) {
                cout << "No" ; 
                return;             
            }
            if (a > b) swap(a, b); 
            ms.insert(mp(a, b)); 
        }
    }
    if (ms.size() != ptr) {
        cout << "No"; 
        return; 
    }
    exit(1); 
    if (ctr == 2) {
        if (ptr > ) cout << "No"; 
        else cout << "Yes";
        return;  
    }          
    if (m == n - 1) {
        if (ptr) cout << "No";
        else cout << "Yes";
        return;   
    }
    if (m <= ctr * (ctr - 1) / 2 + n - ctr) {
        cout << "Yes"; 
        return; 
    }
    cout << "No";     
}                                 
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

Compiler output:
a.cc: In function 'void solve()':
a.cc:102:19: error: expected primary-expression before ')' token
  102 |         if (ptr > ) cout << "No";
      |                   ^
Language: C++

/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=1e5;

int n,q;
long long m;
bool B1;

struct MERGESET{
	int Mfa[N+3],Msiz[N+3];
	void Init(int Nn){
		for(int i=1;i<=Nn;i++)
			Mfa[i]=i,Msiz[i]=1;
	}
	int FindFa(int u){
		if(u==Mfa[u]) return u;
		return Mfa[u]=FindFa(Mfa[u]);
	}
	bool Merge(int u,int v){
		int Fu=FindFa(u),Fv=FindFa(v);
		if(Fu==Fv) return false;
		Mfa[Fu]=Fv;
		Msiz[Fv]+=Msiz[Fu];
		Msiz[Fu]=0;
		return true;
	}
}Mset;

vector< pair<int,int> > Opt1;

int main(){
	scanf("%d%lld%d",&n,&m,&q);
	Mset.Init(n);
	for(int i=1;i<=q;i++){
		int u,v,tmp;
		scanf("%d%d%d",&u,&v,&tmp);
		if(tmp)
			Opt1.emplace_back(u,v),
			B1=true;
		else
			Mset.Merge(u,v);
	}
	for(auto it : Opt1){
		int u=it.first,v=it.second;
		int Fu=Mset.FindFa(u),Fv=Mset.FindFa(v);
		if(Fu==Fv){
			printf("NO\n");
			return 0;
		}
	}
	long long Etot=0,Etre=0;
	for(int i=1;i<=n;i++){
		Etot+=Mset.Msiz[i]-1;
		if(Mset.Msiz[i])
			Etre++;
	}
	if(B1){
		if(Etot+Etre<=m && m<=Etot+Etre*(Etre-1)/2)
			printf("YES\n");
		else
			printf("NO\n");
	}
	else{
		if(Etot+Etre-1<=m && m<=Etot+Etre*(Etre-1)/2)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

Compiler output:
a.cc:33:1: error: 'vector' does not name a type
   33 | vector< pair<int,int> > Opt1;
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:42:25: error: 'Opt1' was not declared in this scope
   42 |                         Opt1.emplace_back(u,v),
      |                         ^~~~
a.cc:47:23: error: 'Opt1' was not declared in this scope
   47 |         for(auto it : Opt1){
      |                       ^~~~
a.cc:49:54: error: 'v' was not declared in this scope; did you mean 'Fv'?
   49 |                 int Fu=Mset.FindFa(u),Fv=Mset.FindFa(v);
      |                                                      ^
      |                                                      Fv
Language: C++

#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long ll;
const int Maxn = 1e5;

int N, K;
ll M;
vector<pair<int, int> > t;

int fa[Maxn + 5];
int find(int x) {
	if(x == fa[x]) return x;
	return fa[x] = find(fa[x]);
}

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%d %lld %d", &N, &M, &K);
	for(int i = 1; i <= N; i++)
		fa[i] = i;
	for(int i = 1; i <= K; i++) {
		int u, v, typ;
		scanf("%d %d %d", &u, &v, &typ);
		u++, v++;
		if(typ == 0) {
			int fu = find(u), fv = find(v);
			if(fu != fv) fa[fu] = fv;
		} else t.push_back(make_pair(u, v));
	}
	int cnt = 0;
	for(int i = 1; i <= N; i++)
		if(i == find(i)) cnt++;
	ll mx = 1LL * cnt * (cnt - 1) / 2 + N - cnt;
	if(mx < M) {
		puts("No");
		return 0;
	}
	ll mn = (t.empty() ? N - 1 : N);
	if(mn > M) {
		puts("No");
		return 0;
	}
	for(int i = 0; i < (int)t.size(); i++)
		if(find(t[i].first) == find(t[i].second)) {
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}

Compiler output:
a.cc:10:1: error: 'vector' does not name a type
   10 | vector<pair<int, int> > t;
      | ^~~~~~
a.cc: In function 'int main()':
a.cc:33:24: error: 't' was not declared in this scope
   33 |                 } else t.push_back(make_pair(u, v));
      |                        ^
a.cc:43:18: error: 't' was not declared in this scope
   43 |         ll mn = (t.empty() ? N - 1 : N);
      |                  ^
Language: C++

#include <bits/stdc++.h>
#define mem(s,t) memset(s,t,sizeof(s))
#define pb(s) push_back(s)
#define inf 0x3f3f3f3f
#define mn 100010
typedef long long ll;
using namespace std;

int n,m,q;
vector<int> root;
int f[100010],a[mn],b[mn],c[mn];
int vis[100010];
vector<int> e[100010];

int sf(int x)
{
    return x==f[x]?x:f[x]=sf(f[x]);
}

void init()
{
    int i,j;
    for (i=0;i<=n;i++)
    {
        f[i]=i;
        vis[i]=0;
        e[i].clear();
    }
    root.clear();
}

int main()
{
    int i,j,k;
    scanf("%d%d%d",&n,&m,&q);
    init();
    for (i=1;i<=q;i++)
    {
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
    }

    for (i=1;i<=q;i++)
    if (c[i]==0)
    {
        f[sf(a[i])]=sf(b[i]);
    }

    bool ff=true;
    for (i=1;i<=q;i++)
    if (c[i]==1)
    {
        if (sf(a[i])==sf(b[i])) ff=false;
    }
    for (i=0;i<n;i++)
        vis[f[i]]=1;
    int sum=0;
    for (i=0;i<n;i++)
        sum+=vis[i];
    if (sum<3||ff=false) printf("No\n");
    else
    {
        //if ((m<n&&root.size()!=0)||m>(n-sum+(sum-1)*sum/2))
        //    printf("No\n");
        printf("Yes\n");
    }
    return 0;
}



Compiler output:
a.cc: In function 'int main()':
a.cc:59:14: error: lvalue required as left operand of assignment
   59 |     if (sum<3||ff=false) printf("No\n");
      |         ~~~~~^~~~
Language: C++

#include <bits/stdc++.h>
#define Hina ios_base::sync_with_stdio(false), cin.tie(0)
#define MAXN 100000
#define pb push_back
#define int long long
using namespace std;

int n, m, q, k;
int a, b, c;
int dsu[MAXN+5];
bool tf = 1, p;
vector < pair<int,int> > arr;

int finding(int a) {
    if (dsu[a] != a) dsu[a] = finding(dsu[a]);
    return dsu[a];
}

signed main() {
    Hina;
    cin >> n >> m >> q;
    for (int i = 0; i < n; i++) dsu[i] = i;
    k = n;
    for (int i = 0; i < q; i++) {
        cin >> a >> b >> c;
        if (finding(a) != finding(b) && c == 0) {
            dsu[finding(a)] = finding(b);
            k--;
        } else if (finding(a) == finding(b) && c != 0) {
            arr.pb(a, b);
        }
        if (c) p = 1;
    }
    for (int i = 0; i < arr.size(); i++) {
        if (finding(arr[i].first) == finding(arr[i].second)) {
            tf = 0;
        }
    }
    if (m > n-k + k*(k-1)/2 || (k<=2 && p)) tf = 0;
    if (tf) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:30:19: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(long long int&, long long int&)'
   30 |             arr.pb(a, b);
      |             ~~~~~~^~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; value_type = std::pair<long long int, long long int>]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note:   candidate expects 1 argument, 2 provided
Language: C++


/// @file up.cc
/// @brief up の実装ファイル
/// @author Yusuke Matsunaga (松永 裕介)
///
/// Copyright (C) 2019 Yusuke Matsunaga
/// All rights reserved.


#include <iostream>
#include <vector>
#include <list>

using namespace std;

class MFSetCell
{
public:

  int mId;

  MFSetCell* mParent;

  int mRank;

};

class MFSet
{
public:

  MFSet(int num);

  ~MFSet() = default;

  int
  find(int id);

  int
  merge(int id1,
	int id2);


private:

  MFSetCell*
  _find_top(MFSetCell* cell);

  vector<MFSetCell> mArray;

};


MFSet::MFSet(int num) :
  mArray(num)
{
  for ( int i = 0; i < num; ++ i ) {
    MFSetCell& cell = mArray[i];
    cell.mId = i;
    cell.mParent = &cell;
    cell.mRank = 0;
  }
}

int
MFSet::find(int id)
{
  auto tmp = &mArray[id];
  auto top = _find_top(tmp);
  return top->mId;
}

MFSetCell*
MFSet::_find_top(MFSetCell* cell)
{
  auto parent = cell->mParent;
  while ( parent->mParent != parent ) {
    cell = cell->mParent = parent->mParent;
    parent = cell->mParent;
  }
  return parent;
}

int
MFSet::merge(int id1,
	     int id2)
{
  auto cell1 = &mArray[id1];
  auto cell2 = &mArray[id2];

  if ( cell1->mParent != cell1 ) {
    cell1 = _find_top(cell1);
  }
  if ( cell2->mParent != cell2 ) {
    cell2 = _find_top(cell2);
  }
  if ( cell1 == cell2 ) {
    return cell1->mId;
  }

  if ( cell1->mRank > cell2->mRank ) {
    cell2->mParent = cell1;
    return cell1->mId;
  }
  else if ( cell1->mRank == cell2->mRank ) {
    ++ cell1->mRank;
    cell2->mParent = cell1;
    return cell1->mId;
  }
  else {
    cell1->mParent = cell2;
    return cell2->mId;
  }
}

void
no()
{
  cout << "No" << endl;
  exit(0);
}

void
yes()
{
  cout << "Yes" << endl;
  exit(0);
}

int
main(int argc,
     char** argv)
{
  int N;
  int M;
  int Q;
  cin >> N >> M >> Q;

  MFSet mfset(N);

  vector<pair<int, int>> multi_pair_list;
  bool has_single = false;
  for ( int i = 0; i < Q; ++ i ) {
    int a, b, c;
    cin >> a >> b >> c;
    if ( c == 0 ) {
      mfset.merge(a, b);
      has_single = true;
    }
    else {
      multi_pair_list.push_back(make_pair(a, b));
    }
  }

  if ( M == N - 1 ) {
    // M = N - 1 の時は木構造のグラフとなる．
    if ( multi_pair_list.size() > 0 ) {
      // その場合複数経路はありえない．
      no();
    }
    else {
      yes();
    }
  }

#if 0
  if ( !has_single ) {
    yes();
  }
#endif

  int K = 0;
  for ( int i = 0; i < N; ++ i ) {
    if ( mfset.find(i) == i ) {
      ++ K;
    }
  }

  if ( K == 2 ) {
    K = 1;
  }

  int M_max = N + (K * (K - 3)) / 2;
  if ( M > M_max ) {
    no();
  }

  for ( auto p: multi_pair_list ) {
    int a = p.first;
    int b = p.second;
    if ( mfset.find(a) == mfset.find(b) ) {
      if ( !has_single() ) {
	abort();
      }
      no();
    }
  }

  yes();

  return 0;
}


Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:192:23: error: 'has_single' cannot be used as a function
  192 |       if ( !has_single() ) {
      |             ~~~~~~~~~~^~
Language: C++


/// @file up.cc
/// @brief up の実装ファイル
/// @author Yusuke Matsunaga (松永 裕介)
///
/// Copyright (C) 2019 Yusuke Matsunaga
/// All rights reserved.


#include <iostream>
#include <vector>

using namespace std;

void
dfs(int i,
    int gid,
    vector<int>& group_id,
    const vector<vector<int>>& adj_list)
{
  if ( group_id[i] != -1 ) {
    return;
  }
  group_id[i] = gid;
  for ( int j: adj_list[i] ) {
    dfs(j, gid, group_id, adj_list);
  }
}

int
main(int argc,
     char** argv)
{
  int N;
  int M;
  int Q;
  cin >> N >> M >> Q;

  vector<pair<int, int>> single_pair_list;
  vector<pair<int, int>> multi_pair_list;
  for ( int i = 0; i < Q; ++ i ) {
    int a, b, c;
    cin >> a >> b >> c;
    if ( c == 0 ) {
      single_pair_list.push_back(make_pair(a, b));
    }
    else {
      multi_pair_list.push_back(make_pair(a, b));
    }
  }

  if ( M == N - 1 ) {
    // M = N - 1 の時は木構造のグラフとなる．
    if ( multi_pair_list.size() > 0 ) {
      // その場合複数経路はありえない．
      cout << "No" << endl;
      return 0;
    }
    else {
      cout << "Yes" << endl;
      return 0;
    }
  }

  vector<vector<int>> adj_list(N);
  for ( auto p: single_pair_list ) {
    int a = p.first;
    int b = p.second;
    adj_list[a].push_back(b);
    adj_list[b].push_back(a);
  }

  vector<int> group_id(N, -1);
  int K = 0;
  for ( int i = 0; i < N; ++ i ) {
    if ( group_id[i] != -1 ) {
      continue;
    }
    dfs(i, K, group_id, adj_list);
    ++ K;
  }


  for ( auto p: multi_pair_list ) {
    int a = p.first;
    int b = p.second;
    if ( group_id[a] == group_id[b] ) {
      cout << "No" << endl;
      return 0;
    }
  }

#if 0
  if ( K == 2 ) {
    abort();
    K = 1;
  }
#endif

  if ( !ng && M <= N + K * (K - 3) / 2 ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}


Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:100:9: error: 'ng' was not declared in this scope
  100 |   if ( !ng && M <= N + K * (K - 3) / 2 ) {
      |         ^~
Language: C++


/// @file up.cc
/// @brief up の実装ファイル
/// @author Yusuke Matsunaga (松永 裕介)
///
/// Copyright (C) 2019 Yusuke Matsunaga
/// All rights reserved.


#include <iostream>
#include <vector>

using namespace std;

void
dfs(int i,
    int gid,
    vector<int>& group_id,
    const vector<vector<int>>& adj_list)
{
  if ( group_id[i] != -1 ) {
    return;
  }
  group_id[i] = gid;
  for ( int j: adj_list[i] ) {
    dfs(j, gid, group_id, adj_list);
  }
}

int
main(int argc,
     char** argv)
{
  int N;
  int M;
  int Q;
  cin >> N >> M >> Q;

  vector<vector<int>> adj_list(N);
  vector<pair<int, int>> multi_pair_list;
  vector<int> group_id(N, -1);
  int K = 0;

  for ( int i = 0; i < Q; ++ i ) {
    int a, b, c;
    cin >> a >> b >> c;
    if ( c == 0 ) {
      adj_list[a].push_back(b);
      adj_list[b].push_back(a);
    }
    else {
      multi_pair_list.push_back(make_pair(a, b));
    }
  }

  if ( M == N - 1 ) {
    // M = N - 1 の時は木構造のグラフとなる．
    if ( multi_pair_list.size() > 0 ) {
      // その場合複数経路はありえない．
      cout << "No" << endl;
      return 0;
    }
    else {
      cout << "Yes" << endl;
      return 0;
    }
  }

  for ( int i = 0; i < N; ++ i ) {
    if ( group_id[i] != -1 ) {
      continue;
    }
    dfs(i, K, group_id, adj_list);
    ++ K;
  }

  bool ng = false;
  for ( auto p: multi_pair_list ) {
    int a = p.first;
    int b = p.second;
    if ( group_id[a] == group_id[b] ) {
      cout << "No" << endl;
      return;
      ng = true;
      break;
    }
  }

#if 0
  if ( K == 2 ) {
    abort();
    K = 1;
  }
#endif

  if ( !ng && M <= N + K * (K - 3) / 2 ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}


Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:83:7: error: return-statement with no value, in function returning 'int' [-fpermissive]
   83 |       return;
      |       ^~~~~~
Language: C

//边数爆int!!! 
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
const int N=1e5+10;
struct apple
{
	int x,y;
}edge[N];
int k,f[N];
long long cnt;
void push_back(int x,int y)
{
	edge[++k].x=x;
	edge[k].y=y;
 } 
int find(int x)
{
	if(f[x]==x)
		return x;
	f[x]=find(f[x]);
	return f[x];
}
void unioned(int x,int y)
{
	int fx,fy;
	fx=find(x);
	fy=find(y);
	if(fx!=fy)
	{
		f[fx]=fy;
		cnt--;
	} 
}
int judge(int x,int y)
{
	int fx,fy;
	fx=find(x);
	fy=find(y);
	if(fx==fy)
		return 0;
	return 1;
}
int main()
{
	int fla,q,i,x,y,z;
	long long n,m;
	fla=1;
	k=0;
	scanf("%lld%lld%d",&n,&m,&q);
	cnt=n;
	for(i=1;i<=n;i++)
		f[i]=i;
	for(i=1;i<=q;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		x++;
		y++;
		if(z==0)
			unioned(x,y);
		else
			push_back(x,y);
	}
	//for(i=1;i<=n;i++)
	//	printf("%d ",f[i]);
	//printf("\n");
	if(m==n-1)
	{
		if(k>0)
			printf("No");
		else
			printf("Yes");
		return 0;
	}
	for(i=1;i<=k;i++)
		if(!judge(edge[i].x,edge[i].y))
			fla=0;
	//printf("%d\n",fla);
	if(m>n-cnt+cnt*(cnt-1)/2)
		fla=0;
	if(fla)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Compiler output:
main.c:10:2: error: variably modified 'edge' at file scope
   10 | }edge[N];
      |  ^~~~
main.c:11:7: error: variably modified 'f' at file scope
   11 | int k,f[N];
      |       ^
Language: C

//边数爆int!!! 
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<iostream.h>
const int N=1e5+10;
struct apple
{
	int x,y;
}edge[N];
int k,f[N];
long long cnt;
void push_back(int x,int y)
{
	edge[++k].x=x;
	edge[k].y=y;
 } 
int find(int x)
{
	if(f[x]==x)
		return x;
	f[x]=find(f[x]);
	return f[x];
}
void unioned(int x,int y)
{
	int fx,fy;
	fx=find(x);
	fy=find(y);
	if(fx!=fy)
	{
		f[fx]=fy;
		cnt--;
	} 
}
int judge(int x,int y)
{
	int fx,fy;
	fx=find(x);
	fy=find(y);
	if(fx==fy)
		return 0;
	return 1;
}
int main()
{
	int fla,q,i,x,y,z;
	long long n,m;
	fla=1;
	k=0;
	scanf("%lld%lld%d",&n,&m,&q);
	cnt=n;
	for(i=1;i<=n;i++)
		f[i]=i;
	for(i=1;i<=q;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		x++;
		y++;
		if(z==0)
			unioned(x,y);
		else
			push_back(x,y);
	}
	//for(i=1;i<=n;i++)
	//	printf("%d ",f[i]);
	//printf("\n");
	if(m==n-1)
	{
		if(k>0)
			printf("No");
		else
			printf("Yes");
		return 0;
	}
	for(i=1;i<=k;i++)
		if(!judge(edge[i].x,edge[i].y))
			fla=0;
	//printf("%d\n",fla);
	if(m>n-cnt+cnt*(cnt-1)/2)
		fla=0;
	if(fla)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Compiler output:
main.c:6:9: fatal error: iostream.h: No such file or directory
    6 | #include<iostream.h>
      |         ^~~~~~~~~~~~
compilation terminated.
Language: C


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<iostream>
const int N=1e5+10;
struct apple
{
	int x,y;
}edge[N];
int k,f[N];
long long cnt;
void push_back(int x,int y)
{
	edge[++k].x=x;
	edge[k].y=y;
 } 
int find(int x)
{
	if(f[x]==x)
		return x;
	f[x]=find(f[x]);
	return f[x];
}
void unioned(int x,int y)
{
	int fx,fy;
	fx=find(x);
	fy=find(y);
	if(fx!=fy)
	{
		f[fx]=fy;
		cnt--;
	} 
}
int judge(int x,int y)
{
	int fx,fy;
	fx=find(x);
	fy=find(y);
	if(fx==fy)
		return 0;
	return 1;
}
int main()
{
	int fla,q,i,x,y,z;
	long long n,m;
	fla=1;
	k=0;
	scanf("%lld%lld%d",&n,&m,&q);
	cnt=n;
	for(i=1;i<=n;i++)
		f[i]=i;
	for(i=1;i<=q;i++)
	{
		scanf("%d%d%d",&x,&y,&z);
		x++;
		y++;
		if(z==0)
			unioned(x,y);
		else
			push_back(x,y);
	}
	//for(i=1;i<=n;i++)
	//	printf("%d ",f[i]);
	//printf("\n");
	if(m==n-1)
	{
		if(k>0)
			printf("No");
		else
			printf("Yes");
		return 0;
	}
	for(i=1;i<=k;i++)
		if(!judge(edge[i].x,edge[i].y))
			fla=0;
	//printf("%d\n",fla);
	if(m>n-cnt+cnt*(cnt-1)/2)
		fla=0;
	if(fla)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Compiler output:
main.c:6:9: fatal error: iostream: No such file or directory
    6 | #include<iostream>
      |         ^~~~~~~~~~
compilation terminated.
Language: C++

#include <iostream>
#include <vector>

struct DJSet {
  int n;
  std::vector<int> upper;

  DJSet(int n) : upper(n) {
    for (int i=0;i<n;++i) upper[i]=-1;
  }

  int root(int x) {
    return upper[x]<0?x:(upper[x]=root(upper[x]));
  }

  bool equiv(int x, int y) {
    return root(x)==root(y);
  }

  void setUnion(int x, int y) {
    x=root(x);
    y=root(y);
    if (x==y) return;
    if (upper[x]>upper[y]) {
      x^=y;
      y^=x;
      x^=y;
    }
    upper[x]+=upper[y];
    upper[y]=x;
  }
};

int main() {
  int N, M, Q;
  std::cin >> N >> M >> Q;
  DJSet ds(N);
  std::vector<int> A(Q);
  std::vector<int> B(Q);
  std::vector<int> C(Q);
  for (int i=0;i<Q;++i) {
    std::cin >> A[i] >> B[i] >> C[i];
    if (C[i]==0) {
      ds.setUnion(A[i], B[i]);
    }
  }
  bool flag=false;
  for (int i=0;i<Q;++i) {
    if (C[i]==1) {
      flag=true;
      if (ds.equiv(A[i], B[i])) {
	std::cout << "No" << std::endl;
	return 0;
      }
    }
  }
  int num=0;
  for (int i=0;i<N;++i) {
    if (ds.upper[i]<0) ++num;
  }
  if (N-1+(numn-2)*(num-1)/2<M) {
    std::cout << "No" << std::endl;
  }
  if (M<N-1+(flag?1:0)) {
    std::cout << "No" << std::endl;
    return 0;
  }
  if (num==2) {
    std::cout << "No" << std::endl;
    return 0;
  }
  std::cout << "Yes" << std::endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:61:12: error: 'numn' was not declared in this scope; did you mean 'num'?
   61 |   if (N-1+(numn-2)*(num-1)/2<M) {
      |            ^~~~
      |            num
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  //木の根なら-(size of tree) それ以外は木の根のindexが入っている。  
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n,m,q;
  cin >> n >> m >> q;
  ll a[q],b[q],c[q];
  UnionFind s(n);
  rep(i,q){
    cin >> a[i] >> b[i] >> c[i];
    if(c[i]==0) s.unite(a[i],b[i]);
  }
  ll ed=m;
  int cc=0;
  ll v=0;
  rep(i,n){
    if(s.root(i)==i){
      v++;
      cc++;
      ed-=s.size(i)-1;
    }
  }
  bool ok=true;
  if(ed<0) ok=false;

  bool loop=false;

  rep(i,q){
    if(c[i]==1){
      loop=true;
      if(s.same(a[i],b[i])) ok=false;
    }
  }
  if(!loop){
    if(n-1!=m) ok=false;
  }
  else if(v>=3){
    if(m>n+c*(c-3)/2) ok=false;
      //    if((v*(v-1)/2<ed)) ok=false;
  }
  else ok=false;

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
    

  
  return 0;
    

}


Compiler output:
a.cc: In function 'int main()':
a.cc:69:13: error: invalid operands of types 'll [q]' {aka 'long long int [q]'} and 'll*' {aka 'long long int*'} to binary 'operator*'
   69 |     if(m>n+c*(c-3)/2) ok=false;
      |            ~^~~~~~
      |            |   |
      |            |   ll* {aka long long int*}
      |            ll [q] {aka long long int [q]}
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

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

int main(){
  //  ios::sync_with_stdio(false);
  //  cin.tie(0);

  ll n,m,q;
  cin >> n >> m >> q;
  //  ll a[n],b[n],c[n];
  UnionFind uf(n);
  rep(i,q){
    //    cin >> a[i] >> b[i] >> c[i];
    //    while(q--){
    int x,y,t;
    cin>>x>>y>>t;
    //    a[i]=x;b[i]=y;c[i]=t;
    if(t){
      //     edge.emplace_back(x,y);
    }
    else {
      if(uf.unite(x,y)){
      }
    }
  }
  // if(c[i]==0) s.unite(a[i],b[i]);
  //  }
  ll ed=m;
  ll v=0;
   cout << "Yes" << endl;
  return 0;
  rep(i,n){
    if(uf.find(i)==i){
      v++;
      ed-=uf.size(i)-1;
    }
  }
  cout << "Yes" << endl;
  return 0;
  bool ok=true;
  if(ed<0) ok=false;

  bool loop=false;
  rep(i,q){
    if(c[i]==1){
      loop=true;
      if(uf.same(a[i],b[i])) ok=false;
    }
  }
  if(!loop){
    if((v*(v-1)/2<ed) ||( v-1>ed)) ok=false;
  }
  else if(v>=3){
    if((v*(v-1)/2<ed) ||( v-1>ed)) ok=false;
  }
  else ok=false;

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
    

  
  return 0;
    

}


Compiler output:
a.cc: In function 'int main()':
a.cc:80:8: error: 'c' was not declared in this scope
   80 |     if(c[i]==1){
      |        ^
a.cc:82:18: error: 'a' was not declared in this scope
   82 |       if(uf.same(a[i],b[i])) ok=false;
      |                  ^
a.cc:82:23: error: 'b' was not declared in this scope
   82 |       if(uf.same(a[i],b[i])) ok=false;
      |                       ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

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

int main(){
  //  ios::sync_with_stdio(false);
  //  cin.tie(0);

  ll n,m,q;
  cin >> n >> m >> q;
  //  ll a[n],b[n],c[n];
  UnionFind uf(n);
  rep(i,q){
    //    cin >> a[i] >> b[i] >> c[i];
    //    while(q--){
    int x,y,t;
    cin>>x>>y>>t;
    //    a[i]=x;b[i]=y;c[i]=t;
    if(t){
      //     edge.emplace_back(x,y);
    }
    else {
      if(uf.unite(x,y)){
      }
    }
  }
  // if(c[i]==0) s.unite(a[i],b[i]);
  //  }
  ll ed=m;
  ll v=0;
  rep(i,n){
    if(uf.find(i)==i){
      v++;
      ed-=uf.size(i)-1;
    }
  }
  cout << "Yes" << endl;
  return 0;
  bool ok=true;
  if(ed<0) ok=false;

  bool loop=false;
  rep(i,q){
    if(c[i]==1){
      loop=true;
      if(uf.same(a[i],b[i])) ok=false;
    }
  }
  if(!loop){
    if((v*(v-1)/2<ed) ||( v-1>ed)) ok=false;
  }
  else if(v>=3){
    if((v*(v-1)/2<ed) ||( v-1>ed)) ok=false;
  }
  else ok=false;

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
    

  
  return 0;
    

}


Compiler output:
a.cc: In function 'int main()':
a.cc:78:8: error: 'c' was not declared in this scope
   78 |     if(c[i]==1){
      |        ^
a.cc:80:18: error: 'a' was not declared in this scope
   80 |       if(uf.same(a[i],b[i])) ok=false;
      |                  ^
a.cc:80:23: error: 'b' was not declared in this scope
   80 |       if(uf.same(a[i],b[i])) ok=false;
      |                       ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll n,m,q;
  cin >> n >> m >> q;
  ll a[n],b[n],c[n];
  UnionFind s(n);
  rep(i,q){
    cin >> a[i] >> b[i] >> c[i];
    asert(n!=1e5);
    if(c[i]==0) s.unite(a[i],b[i]);
  }
  ll ed=m;
  ll v=0;
  rep(i,n){
    if(s.find(i)==i){
      v++;
      ed-=s.size(i)-1;
    }
  }
  bool ok=true;
  if(ed<0) ok=false;

  bool loop=false;
  rep(i,q){
    if(c[i]==1){
      loop=true;
      if(s.same(a[i],b[i])) ok=false;
    }
  }
  if(!loop){
    if((v*(v-1)/2<ed) ||( v-1>ed)) ok=false;
  }
  else if(v>=3){
    if((v*(v-1)/2<ed) ||( v-1>ed)) ok=false;
  }
  else ok=false;

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
    

  
  return 0;
    

}


Compiler output:
a.cc: In function 'int main()':
a.cc:49:5: error: 'asert' was not declared in this scope; did you mean 'assert'?
   49 |     asert(n!=1e5);
      |     ^~~~~
      |     assert
Language: C++

#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 1010000
struct UnionFind{
    vector<int> par,sizes;
    UnionFind(int n):par(n+1),sizes(n+1,1){
        rep2(i,1,n)par[i]=i;
    }
    int find(int x){
        return (x==par[x]?x:par[x]=find(par[x]));
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return ;
        if(sizes[x]<sizes[y]){
            swap(x,y);
        }
        par[y]=x;
        sizes[x]+=sizes[y];
    }
    bool same(int x,int y) {return (find(x)==find(y));}
    int size(int x) {return sizes[find(x)];}
};

main(){
  ll n=in(),m=in();
  int q=in();
  UnionFind uf(n);
  vector<pii> v;
  rep(i,q){
    int a,b,c;
    cin>>a>>b>>c;
    if(!c){
      uf.unite(a,b);
    }
    else v.pb({a,b});
  }
  bool flag=true;
  for(auto e:v){
    if(uf.same(e.first,e.second))flag=false;
    else {
      uf.unite(e.first,e.second);
    }
  }
  ll cnt=0;
  rep(i,n){
    if(uf.par[i]==i)cnt++;
  }
  if(v.size()&&(m==n-1)){
    flag=false;
  }
  if(m>n+(cnt*(cnt-3))/2))flag=false;
  cout<<(flag?"Yes":"No");
}


Compiler output:
a.cc:68:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   68 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:95:26: error: expected primary-expression before ')' token
   95 |   if(m>n+(cnt*(cnt-3))/2))flag=false;
      |                          ^
Language: C++

#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 1010000
struct UnionFind{
    vector<int> par,sizes;
    UnionFind(int n):par(n+1),sizes(n+1,1){
        rep2(i,1,n)par[i]=i;
    }
    int find(int x){
        return (x==par[x]?x:par[x]=find(par[x]));
    }
    void unite(int x,int y){
        x=find(x);y=find(y);
        if(x==y)return ;
        if(sizes[x]<sizes[y]){
            swap(x,y);
        }
        par[y]=x;
        sizes[x]+=sizes[y];
    }
    bool same(int x,int y) {return (find(x)==find(y));}
    int size(int x) {return sizes[find(x)];}
};

main(){
  ll n=in(),m=in();
  int q=in();
  UnionFind uf(n);
  vector<pii> v;
  rep(i,q){
    int a,b,c;
    cin>>a>>b>>c;
    if(!c){
      uf.unite(a,b);
    }
    else v.pb({a,b});
  }
  bool flag=true;
  for(auto e:v){
    if(uf.same(e.first,e.second))flag=false;
    else {
      uf.unite(e.first,e.second);
    }
  }
  ll cnt=0;
  rep(i,n){
    if(uf.par[i]==i)cnt++;
  }
  if(v.size()&&(m==n-1)){
    flag=false;
  }
  if(M>n+(cnt*(cnt-3))/2))flag=false;
  cout<<(flag?"Yes":"No");
}

Compiler output:
a.cc:68:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   68 | main(){
      | ^~~~
a.cc: In function 'int main()':
a.cc:95:6: error: 'M' was not declared in this scope
   95 |   if(M>n+(cnt*(cnt-3))/2))flag=false;
      |      ^
a.cc:95:26: error: expected primary-expression before ')' token
   95 |   if(M>n+(cnt*(cnt-3))/2))flag=false;
      |                          ^
Language: C++

#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

class union_find_tree {
	std::vector<int> data;

	public:
	union_find_tree(const size_t && N)
		: data(N, -1) {}
	const bool unite(size_t x, size_t y) {
		x = find(x); y = find(y);
		if(x == y) return false;
		if(data[x] > data[y]) std::swap(x, y);
		
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	const size_t find(size_t k) {
		if(data[k] < 0) return k;
		return data[k] = find(data[k]);
	}
	const size_t component_size(const size_t && k) {
		return -data[find(k)];
	}
	const bool same(const size_t && x, const size_t && y) {
		return find(x) == find(y);
	}
	
	void clear() { data.assign(size(), -1); }
	const size_t size() const { return data.size(); }
};

int main() {
	int n, m, q; scanf("%d%d%d", &n, &m, &q);
	std::vector<int> a(q), b(q), c(q);
	std::vector<int> A, B;
	for(int i = 0; i < q; i++) {
		scanf("%d%d%d", &a[i], &b[i], &c[i]);

		if(c[i] == 0) A.push_back(i);
		else B.push_back(i);
	}

	int tmp = 0;
	bool ans = true;
	i64 latte = A.size();
	i64 malta = A.size();
	union_find_tree uf(n);
	std::vector<bool> used(n, false);
	std::vector<std::pair<int, int>> edge;
	for(auto i: B) uf.unite(a[i], b[i]);
	for(auto i: B) {
		int c = uf.find(a[i]);
		if(used[c]) continue; used[c] = true;

		i64 cs = uf.component_size(a[i]);
		malta += cs * (cs - 1) / 2LL;
		if(cs == 2) {
			edge.push_back({a[i], b[i]});
			latte++;
		} else latte += cs;
	}
	for(auto i: A) if(uf.same(a[i], b[i])) ans = false;

	i64 ma = 0;
	std::vector<bool> kiri(n, false);	
	for(auto i: A) {
		kiri[uf.find(a[i])] = kiri[uf.find(b[i])] = true;
		i64 X = uf.component_size(a[i]);
		i64 Y = uf.component_size(b[i]);
		ma = std::max({ma, X, Y});
	}

	i64 tan = 0;
	for(int i = 0; i < n; i++) if(!kiri[uf.find(i)]) tan++;

	i64 una = 0;
	std::vector<int> beet(n, 0);
	for(auto e: edge)beet[uf.find(e.first)]++;
	for(auto v: beet) {
		if(!v) continue;

		if(v == 1) {
			una++;
		} else {
			ma = std::max<i64>(ma, 3LL);
			latte += v * 2;
			malta += 2;
			tan -= v;
		}
	}
	if(una == 1) {
		latte += 2;
		matla += 2;
		tan--;
	} else {
		latte += una;
		malta += (una * 2) * (una * 2 - 1) / 2LL - una;
	}
	if(tan < 0) ans = false;

	malta += tan * ma + tan * (tan - 1) / 2LL;
	if(!(latte <= m and m <= malta)) ans = false;

	for(auto i: A) {
		if(!uf.unite(a[i], b[i])) {
			ans = false;
		}
	}
	
	if(ans) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:107:17: error: 'matla' was not declared in this scope; did you mean 'malta'?
  107 |                 matla += 2;
      |                 ^~~~~
      |                 malta
Language: C++

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct UnionFind{
  Int num;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int n):num(n),r(n,1),p(n,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
    num--;
  }
  Int size(Int x){
    return r[find(x)];
  }
  Int count() const{
    return num;
  }
};


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int n,m,q;
  cin>>n>>m>>q;
  vector<Int> as(q),bs(q),cs(q);
  for(Int i=0;i<q;i++) cin>>as[i]>>bs[i]>>cs[i];

  // UF for BCC
  UnionFind bc(n),uf(n);
  for(Int i=0;i<q;i++){
    if(cs[i]!=1) continue;
    bc.unite(as[i],bs[i]);
    uf.unite(as[i],bs[i]);
  }

  using P = pair<Int, Int>;
  set<P> sp;
  for(Int i=0;i<q;i++){
    if(cs[i]!=0) continue;
    if(uf.same(as[i],bs[i])) drop("No");
    uf.unite(as[i],bs[i]);
    sp.empalce(min(as[i],bs[i]),max(as[i],bs[i]));
    //num++;
  }
  Int num=sp.size();

  // assert(0);

  // isolated
  Int cnt=0;

  // # components that its size is 2
  Int v2=0;

  // lower_bound
  Int lb=num;
  for(Int i=0;i<n;i++){
    if(uf.size(i)==1){
      // isolated
      cnt++;
      continue;
    }
    if(bc.find(i)!=i) continue;
    Int sz=bc.size(i);
    if(sz==1) continue;
    if(sz==2) v2++;
    if(sz>=3) lb+=sz;
  }

  // check connected
  {
    Int sz=0;
    for(Int i=0;i<n;i++) chmax(sz,uf.size(i));
    // 1 component + isolated vertices
    assert(sz+cnt==n);
    assert(uf.count()==cnt+1);
  }

  // only connected !!?!?!!

  // number of isolated vertices is not enough
  //cout<<v2<<" "<<cnt<<endl;
  if(v2>cnt+1) drop("No");
  //assert(0);

  cnt-=v2;
  lb+=v2*3;
  lb+=cnt;

  // upper_bound
  Int ub=num,mx=0;
  for(Int i=0;i<n;i++){
    if(uf.size(i)==1) continue;
    if(bc.find(i)!=i) continue;
    Int sz=bc.size(i);
    if(sz==1) continue;
    if(sz<=3) sz=3;
    ub+=sz*(sz-1)/2;
    chmax(mx,sz);
  }
  ub-=mx*(mx-1)/2;
  ub+=(mx+cnt)*(mx+cnt-1)/2;

  if(lb<=m&&m<=ub) drop("Yes");
  drop("No");
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:67:8: error: 'class std::set<std::pair<long long int, long long int> >' has no member named 'empalce'; did you mean 'emplace'?
   67 |     sp.empalce(min(as[i],bs[i]),max(as[i],bs[i]));
      |        ^~~~~~~
      |        emplace
Language: C++

#include <bits/stdc++.h>

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class UnionFind {
	public:
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};


class Solution {
public:
	void solve() {
		int n, m, q;
		cin >> n >> m >> q;
		UnionFind uf0(n), uf1(n), uf01(n);
		vector<pair<int, int>> c0, c1;
		vector<bool> f(n, true);
		for(int Q=0; Q < q; Q++){
			int a, b, c;
			cin >> a >> b >> c;
			if(c == 0){
				c0.push_back(make_pair(a, b));
				m--;
			}
			else c1.push_back(make_pair(a, b));
			f[a] = f[b] = false;
		}
		int sf = accumulate(f.begin(), f.end(), 0);
		for(auto t: c0){
			uf0.unionSet(t.first, t.second);
		}
		for(auto t: c1){
			if(uf0.findSet(t.first, t.second)){
				cout << "No" << endl;
				return;
			}
			uf1.unionSet(uf0.root(t.first), uf0.root(t.second));
		}
		for(int i=0; i < n; i++){
			if(uf1.data[i] == -2){
				sf--;
				m -= 2;
		}
		if(sf < 0 || m < 0)cout << "No" << endl;
		else cout << "Yes" << endl;
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Compiler output:
a.cc:78:2: error: expected '}' at end of input
   78 | }
      |  ^
a.cc:32:16: note: to match this '{'
   32 | class Solution {
      |                ^
a.cc:78:2: error: expected unqualified-id at end of input
   78 | }
      |  ^