Language: C++

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 1e5+23;

int parent[N], size[N];

int findParent(int x) {
  if (x == parent[x]) return x;
  return parent[x] = findParent(parent[x]);
}

void unionize(int a, int b) {
  a = findParent(a);
  b = findParent(b);
  if (a != b) {
    if (size[a] < size[b]) swap(a, b);
    parent[a] = b;
    size[b] += size[a];
  }
}

void solve() {
  int n, m; scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    parent[i] = i;
    size[i] = 1;
  }
  for (int x, y, z, i = 0; i < m; ++i) {
    scanf("%d%d%d", &x, &y, &z);
    unionize(--x, --y);
  }
  set<int> s;
  for (int i = 0; i < n; ++i) s.insert(findParent(i));
  printf("%d", s.size());
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Compiler output:
a.cc: In function 'void unionize(int, int)':
a.cc:28:9: error: reference to 'size' is ambiguous
   28 |     if (size[a] < size[b]) swap(a, b);
      |         ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:17:16: note:                 'int size [100023]'
   17 | int parent[N], size[N];
      |                ^~~~
a.cc:28:19: error: reference to 'size' is ambiguous
   28 |     if (size[a] < size[b]) swap(a, b);
      |                   ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:17:16: note:                 'int size [100023]'
   17 | int parent[N], size[N];
      |                ^~~~
a.cc:30:5: error: reference to 'size' is ambiguous
   30 |     size[b] += size[a];
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:17:16: note:                 'int size [100023]'
   17 | int parent[N], size[N];
      |                ^~~~
a.cc:30:16: error: reference to 'size' is ambiguous
   30 |     size[b] += size[a];
      |                ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:17:16: note:                 'int size [100023]'
   17 | int parent[N], size[N];
      |                ^~~~
a.cc: In function 'void solve()':
a.cc:38:5: error: reference to 'size' is ambiguous
   38 |     size[i] = 1;
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:17:16: note:                 'int size [100023]'
   17 | int parent[N], size[N];
      |                ^~~~