Language: C++

#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
ll n;
vector<vl> adj;
vector<bool> visit;
void dfs(ll node)
{
	visit[node]=true;
	for(auto x: adj[node])
	{
		if(visit[x]==false)
		{
			dfs(x);
		}
	}
}
void solve()
{
	ll m;
    cin>>n>>m;
    visit.resize(n, false);
    adj.resize(n);
    forr(i, m)
    {
    	ll u, v;
    	cin>>u>>v;
    	--u, --v;
    	adj[u].pb(v), adj[v].pb(u);
    }
    ll ans=0;
    forr(i, n)
    {
    	if(visit[i]==false)
    	{
    		dfs(i);
    		ans++;
    	}
    }
    cout<<ans-1<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Compiler output:
a.cc: In function 'void dfs(long long int)':
a.cc:25:9: error: reference to 'visit' is ambiguous
   25 |         visit[node]=true;
      |         ^~~~~
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:22:14: note:                 'std::vector<bool> visit'
   22 | vector<bool> visit;
      |              ^~~~~
a.cc:28:20: error: reference to 'visit' is ambiguous
   28 |                 if(visit[x]==false)
      |                    ^~~~~
/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:22:14: note:                 'std::vector<bool> visit'
   22 | vector<bool> visit;
      |              ^~~~~
a.cc: In function 'void solve()':
a.cc:38:5: error: reference to 'visit' is ambiguous
   38 |     visit.resize(n, false);
      |     ^~~~~
/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:22:14: note:                 'std::vector<bool> visit'
   22 | vector<bool> visit;
      |              ^~~~~
a.cc:50:12: error: reference to 'visit' is ambiguous
   50 |         if(visit[i]==false)
      |            ^~~~~
/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:22:14: note:                 'std::vector<bool> visit'
   22 | vector<bool> visit;
      |              ^~~~~