Language: C++

#include <bits/stdc++.h>
using namespace std;

vector<int> level(100001),comp(100001);

int getComp(int i){
  if(comp[i] != i) comp[i] = getComp(comp,comp[i]);
  return comp[i];
}

void merge(int a,int b){
  a = getComp(comp,a);
  b = getComp(comp,b);
  if(level[a] > level[b]) swap(a,b);
  else if(level[a] == level[b]) ++level[b];
  comp[a] = b;
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,m,x,y,z;
  cin >> n >> m;
  iota(begin(comp),end(comp),0);
  while(m--){
    cin >> x >> y >> z;
    merge(comp,level,x,y);
  }
  set<int> st;
  for(int i = 1; i <= n; ++i) st.insert(getComp(comp,i));
  cout << st.size();
  return 0;
}


Compiler output:
a.cc: In function 'int getComp(int)':
a.cc:7:38: error: cannot convert 'std::vector<int>' to 'int'
    7 |   if(comp[i] != i) comp[i] = getComp(comp,comp[i]);
      |                                      ^~~~
      |                                      |
      |                                      std::vector<int>
a.cc:6:17: note:   initializing argument 1 of 'int getComp(int)'
    6 | int getComp(int i){
      |             ~~~~^
a.cc: In function 'void merge(int, int)':
a.cc:12:15: error: cannot convert 'std::vector<int>' to 'int'
   12 |   a = getComp(comp,a);
      |               ^~~~
      |               |
      |               std::vector<int>
a.cc:6:17: note:   initializing argument 1 of 'int getComp(int)'
    6 | int getComp(int i){
      |             ~~~~^
a.cc:13:15: error: cannot convert 'std::vector<int>' to 'int'
   13 |   b = getComp(comp,b);
      |               ^~~~
      |               |
      |               std::vector<int>
a.cc:6:17: note:   initializing argument 1 of 'int getComp(int)'
    6 | int getComp(int i){
      |             ~~~~^
a.cc: In function 'int main()':
a.cc:27:10: error: no matching function for call to 'merge(std::vector<int>&, std::vector<int>&, int&, int&)'
   27 |     merge(comp,level,x,y);
      |     ~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:4857:5: note: candidate: 'template<class _IIter1, class _IIter2, class _OIter> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter)'
 4857 |     merge(_InputIterator1 __first1, _InputIterator1 __last1,
      |     ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4857:5: note:   candidate expects 5 arguments, 4 provided
/usr/include/c++/14/bits/stl_algo.h:4908:5: note: candidate: 'template<class _IIter1, class _IIter2, class _OIter, class _Compare> _OIter std::merge(_IIter1, _IIter1, _IIter2, _IIter2, _OIter, _Compare)'
 4908 |     merge(_InputIterator1 __first1, _InputIterator1 __last1,
      |     ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4908:5: note:   candidate expects 6 arguments, 4 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:412:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator, class _Compare> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::merge(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _ForwardIterator, _Compare)'
  412 | merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
      | ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:412:1: note:   candidate expects 7 arguments, 4 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:417:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _ForwardIterator> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::merge(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _ForwardIterator)'
  417 | merge(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
      | ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:417:1: note:   candidate expects 6 arguments, 4 provided
a.cc:11:6: note: candidate: 'void merge(int, int)'
   11 | void merge(int a,int b){
      |      ^~~~~
a.cc:11:6: note:   candidate expects 2 arguments, 4 provided
a.cc:30:49: error: cannot convert 'std::vector<int>' to 'int'
   30 |   for(int i = 1; i <= n; ++i) st.insert(getComp(comp,i));
      |                                                 ^~~~
      |                                                 |
      |                                                 std::vector<int>
a.cc:6:17: note:   initializing argument 1 of 'int getComp(int)'
    6 | int getComp(int i){
      |             ~~~~^