Language: C++

#include <bits/stdc++.h>

using namespace std;
const int maxn=1e5+5;

int parent[maxn];
int size[maxn];

void make_set(int v) {
    parent[v] = v;
    size[v]=1;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return find_set(parent[v]);
}

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

int main()
{
    int n,m;
    cin>>n>>m;

    int root=0;

    for(int i=1;i<=n;i++)
        make_set(i);
    
    for(int i=0;i<m;i++)
    {
        int a,b;cin>>a>>b;

        union_sets(a,b);

        if (size[a] < size[b])
            swap(a, b);

        if(size[root]<size[a])
            root=a;
    }

    int cont=0;

    for(int i=1;i<=n;i++)
    {
        if(parent[i]!=root)
        {
            union_sets(root,i);
            cont++;
        } 
    }
    cout<<cont<<'\n';
}

Compiler output:
a.cc: In function 'void make_set(int)':
a.cc:11:5: error: reference to 'size' is ambiguous
   11 |     size[v]=1;
      |     ^~~~
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:7:5: note:                 'int size [100005]'
    7 | int size[maxn];
      |     ^~~~
a.cc: In function 'void union_sets(int, int)':
a.cc:24:13: error: reference to 'size' is ambiguous
   24 |         if (size[a] < size[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:7:5: note:                 'int size [100005]'
    7 | int size[maxn];
      |     ^~~~
a.cc:24:23: error: reference to 'size' is ambiguous
   24 |         if (size[a] < size[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:7:5: note:                 'int size [100005]'
    7 | int size[maxn];
      |     ^~~~
a.cc:27:9: error: reference to 'size' is ambiguous
   27 |         size[a] += size[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:7:5: note:                 'int size [100005]'
    7 | int size[maxn];
      |     ^~~~
a.cc:27:20: error: reference to 'size' is ambiguous
   27 |         size[a] += size[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:7:5: note:                 'int size [100005]'
    7 | int size[maxn];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:47:13: error: reference to 'size' is ambiguous
   47 |         if (size[a] < size[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:7:5: note:                 'int size [100005]'
    7 | int size[maxn];
      |     ^~~~
a.cc:47:23: error: reference to 'size' is ambiguous
   47 |         if (size[a] < size[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:7:5: note:                 'int size [100005]'
    7 | int size[maxn];
      |     ^~~~
a.cc:50:12: error: reference to 'size' is ambiguous
   50 |         if(size[root]<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:7:5: note:                 'int size [100005]'
    7 | int size[maxn];
      |     ^~~~
a.cc:50:23: error: reference to 'size' is ambiguous
   50 |         if(size[root]<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:7:5: note:                 'int size [100005]'
    7 | int size[maxn];
      |     ^~~~