Language: C++

// #include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0; i < n; i++)
#define REPR(i, n) for(long long i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(long long i = m; i <= n; i++)
#define FORR(i, m, n) for(long long i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;

struct UnionFind {
    vector<int> par; 

    UnionFind(int N) : par(N) { 
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry) return; 
        par[rx] = ry; 
    }

    bool same(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){FIN

    int n,m;cin>>n>>m;
    UnionFind tree(n);
    REP(i,m){
        int x,y,z; cin>>x>>y>>z;
        tree.unite(x,y);
    }
    set<int> st;
    REP(i,n){
        st.insert(tree.root(i+1));
    }   
    cout<<st.size()<<endl;
    return 0;
}

Compiler output:
a.cc:13:13: error: 'vector' does not name a type
   13 | using vll = vector<ll>;
      |             ^~~~~~
a.cc:14:14: error: 'vector' does not name a type
   14 | using vvll = vector<vector<ll>>;
      |              ^~~~~~
a.cc:15:11: error: 'pair' does not name a type
   15 | using P = pair<ll, ll>;
      |           ^~~~
a.cc:19:5: error: 'vector' does not name a type
   19 |     vector<int> par;
      |     ^~~~~~
a.cc: In constructor 'UnionFind::UnionFind(int)':
a.cc:21:24: error: class 'UnionFind' does not have any field named 'par'
   21 |     UnionFind(int N) : par(N) {
      |                        ^~~
a.cc:22:36: error: 'par' was not declared in this scope
   22 |         for(int i = 0; i < N; i++) par[i] = i;
      |                                    ^~~
a.cc: In member function 'int UnionFind::root(int)':
a.cc:26:13: error: 'par' was not declared in this scope
   26 |         if (par[x] == x) return x;
      |             ^~~
a.cc:27:16: error: 'par' was not declared in this scope
   27 |         return par[x] = root(par[x]);
      |                ^~~
a.cc: In member function 'void UnionFind::unite(int, int)':
a.cc:34:9: error: 'par' was not declared in this scope
   34 |         par[rx] = ry;
      |         ^~~
a.cc: In function 'int main()':
a.cc:10:13: error: 'ios_base' has not been declared
   10 | #define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
      |             ^~~~~~~~
a.cc:44:12: note: in expansion of macro 'FIN'
   44 | int main(){FIN
      |            ^~~
a.cc:10:47: error: 'cin' was not declared in this scope
   10 | #define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
      |                                               ^~~
a.cc:44:12: note: in expansion of macro 'FIN'
   44 | int main(){FIN
      |            ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | // #include <bits/stdc++.h>
a.cc:10:59: error: 'cout' was not declared in this scope
   10 | #define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
      |                                                           ^~~~
a.cc:44:12: note: in expansion of macro 'FIN'
   44 | int main(){FIN
      |            ^~~
a.cc:10:59: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
   10 | #define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
      |                                                           ^~~~
a.cc:44:12: note: in expansion of macro 'FIN'
   44 | int main(){FIN
      |            ^~~
a.cc:52:5: error: 'set' was not declared in this scope
   52 |     set<int> st;
      |     ^~~
a.cc:1:1: note: 'std::set' is defined in header '<set>'; this is probably fixable by adding '#include <set>'
  +++ |+#include <set>
    1 | // #include <bits/stdc++.h>
a.cc:52:9: error: expected primary-expression before 'int'
   52 |     set<int> st;
      |         ^~~
a.cc:54:9: error: 'st' was not declared in this scope; did you mean 'std'?
   54 |         st.insert(tree.root(i+1));
      |         ^~
      |         std
a.cc:56:11: error: 'st' was not declared in this scope; did you mean 'std'?
   56 |     cout<<st.size()<<endl;
      |           ^~
      |           std
a.cc:56:22: error: 'endl' was not declared in this scope
   56 |     cout<<st.size()<<endl;
      |                      ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | // #include <bits/stdc++.h>