Language: C++

#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=998244353;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
// few lemmas are
// for z is even make them one set
// for z is odd check if it has pair or not if pair put in opposite set
// make new move for finding .
const int nmax = 1e5 + 5 ;
vector < int > root( nmax , 0);
int find_root( int i){
    while(root[ i ] != i){
        root[ i ] = root[ root[ i ] ] ;
        i = root[ i ];
    }
    return i;
}
Union ( int x , int y ){
    int root_x = find_root(x);
    int root_y = find_root(y);
    root[root_x] = root_y ;
}
struct cards{
    int x , y , z ;
};
void solve(){
    int n , m ;
    cin >> n >> m ;
    vector < cards > a(m);
    for( int i = 0 ; i < m ; i++){
        cin >> a[i].x >> a[i].y >> a[i].z ;
    }
    vector < int > marked( n+1 , 0 );
    for( int i = 0 ; i <= n ; i++) root[i] = i ;
    vector <  int > opposite( n+1 , 0 );
    for( int i = 0 ; i < m ; i++){
            if(a[i].z%2==0){
                Union(a[i].x,a[i].y);
            }
            else{
                if(opposite[a[i].x]!=0 || opposite[a[i].y]!=0){
                    if(opposite[a[i].x]!=0){
                        int node = opposite[a[i].x] ;
                        if(node!=0)
                        Union(node,a[i].y) ;
                    }
                    else{
                        int node = opposite[a[i].y];
                        if(node!=0)
                        Union(node,a[i].x);
                    }
                }
                opposite[a[i].x] = a[i].y ;
                opposite[a[i].y] = a[i].x ;
            }
    }
    int ans = 0 ;
//    for( int i = 1 ; i <= n ; i++) cout << root[i] << " " ;
//    cout << "\n" ;
    for( int i = 1 ; i <= n ; i++){
            if(marked[root[i]]==1){
                marked[i] = true ;
                if(opposite[i]!=0){
                    marked[opposite[i]]=1;
                    marked[root[opposite[i]]]=1;
                }
            }
            if(marked[i]==0){
                ans++;
                marked[i]=1;
                marked[root[i]] = 1;
                if(opposite[i]!=0){
                    marked[opposite[i]] = 1 ;
                    marked[root[opposite[i]]] = 1;
                }
            }
//            for( int i = 1 ; i <=n ; i++){
//                cout << marked[i] << " " ;
//            }
//            cout << "\n";
    }
    cout << ans ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


Compiler output:
a.cc:34:1: error: ISO C++ forbids declaration of 'Union' with no type [-fpermissive]
   34 | Union ( int x , int y ){
      | ^~~~~
a.cc: In function 'int Union(int, int)':
a.cc:38:1: warning: no return statement in function returning non-void [-Wreturn-type]
   38 | }
      | ^