Language: C++

#include <bits/stdc++.h>

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

vector<int> ady[maxn];
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;
        ady[a].push_back(b);
        ady[b].push_back(a);

        union_sets(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:12:5: error: reference to 'size' is ambiguous
   12 |     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:8:5: note:                 'int size [100005]'
    8 | int size[maxn];
      |     ^~~~
a.cc: In function 'void union_sets(int, int)':
a.cc:25:13: error: reference to 'size' is ambiguous
   25 |         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:8:5: note:                 'int size [100005]'
    8 | int size[maxn];
      |     ^~~~
a.cc:25:23: error: reference to 'size' is ambiguous
   25 |         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:8:5: note:                 'int size [100005]'
    8 | int size[maxn];
      |     ^~~~
a.cc:28:9: error: reference to 'size' is ambiguous
   28 |         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:8:5: note:                 'int size [100005]'
    8 | int size[maxn];
      |     ^~~~
a.cc:28:20: error: reference to 'size' is ambiguous
   28 |         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:8:5: note:                 'int size [100005]'
    8 | int size[maxn];
      |     ^~~~
a.cc: In function 'int main()':
a.cc:49:12: error: reference to 'size' is ambiguous
   49 |         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:8:5: note:                 'int size [100005]'
    8 | int size[maxn];
      |     ^~~~
a.cc:49:23: error: reference to 'size' is ambiguous
   49 |         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:8:5: note:                 'int size [100005]'
    8 | int size[maxn];
      |     ^~~~