Language: C++

#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define maxn 100001
ll visit[maxn];
void init()
{
    for(int i=0;i<maxn;i++)
    {
        visit[i]=i;
    }
}
ll find(ll x)
{
    if(x!=visit[x])
    {
        return visit[x]=find(visit[x]);
    }
    return x;
}
void Union(ll x,ll y)
{
    ll val=find(x),val1=find(y);
    visit[val]=val1;
}
int main()
{
    fastIO;
    init();
    ll n,m;
    cin>>n>>m;
    pair<ll,ll>p[m];
    for(int i=0;i<m;i++)
    {
        cin>>p[i].fi>>p[i].se;
        Union(p[i].fi,p[i].se);
    }
    map<ll,ll>mp;
    for(int i=1;i<=n;i++)
    {
        mp[find(i)]++;
    }
    cout<<mp.size()-1<<endl;
}

Compiler output:
a.cc: In function 'void init()':
a.cc:55:9: error: reference to 'visit' is ambiguous
   55 |         visit[i]=i;
      |         ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:50:4: note:                 'long long int visit [100001]'
   50 | ll visit[maxn];
      |    ^~~~~
a.cc: In function 'long long int find(long long int)':
a.cc:60:11: error: reference to 'visit' is ambiguous
   60 |     if(x!=visit[x])
      |           ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:50:4: note:                 'long long int visit [100001]'
   50 | ll visit[maxn];
      |    ^~~~~
a.cc:62:16: error: reference to 'visit' is ambiguous
   62 |         return visit[x]=find(visit[x]);
      |                ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:50:4: note:                 'long long int visit [100001]'
   50 | ll visit[maxn];
      |    ^~~~~
a.cc:62:30: error: reference to 'visit' is ambiguous
   62 |         return visit[x]=find(visit[x]);
      |                              ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:50:4: note:                 'long long int visit [100001]'
   50 | ll visit[maxn];
      |    ^~~~~
a.cc: In function 'void Union(long long int, long long int)':
a.cc:69:5: error: reference to 'visit' is ambiguous
   69 |     visit[val]=val1;
      |     ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:50:4: note:                 'long long int visit [100001]'
   50 | ll visit[maxn];
      |    ^~~~~