Language: C++

/**
        Bismilla- hir rahma-nir rahi-m
    @uthor Md Hasibur Rahman (Evan)
                JKKNIU
*/


#include<bits/stdc++.h>
#define         ll              long long
#define         FI              freopen("input.txt","r",stdin)
#define         FO              freopen("output.txt","w",stdout)
#define         PrintCase(i)    printf("Case %d: ",i)
#define         sc(a)           scanf("%d",&a)
#define         scl(a)          scanf("%lld",&a)
#define         rep(i,n)        for(int i=0;i<n;i++)
#define         pb              push_back
#define         MAX             1000000
#define         fast            ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define		   MOD			1000000007;


using namespace std;

bool isPrime(ll a)
{
    for(ll i=2;i*i<=a;i++)
        if(a%i==0)
            return false;
    return true;
}






bool isPowerOfTwo(ll a)
{
    if(a==1)
        return true;
    if(a&1)
        return false;
    while(a)
    {
        a/=2;
        if(a!=1 && a&1)
            return false;
        if(a==1)
            return true;
    }
    return true;
}




ll gcd(ll a, ll b)
{
    if(a<0 || b<0)
    {
        a = abs(a);
        b = abs(b);
    }
    if(a<b)
        swap(a,b);
    if(a%b==0 || b==0)
        return b;
    else
        return gcd(b,a%b);
}



ll lcm(ll a, ll b)
{
    return (a*b)/gcd(a,b);
}



ll power(ll base, ll exponent)
{
    ll ans = 1;
    for(ll i=1;i<=exponent;i++)
        ans*=base;
    return ans;
}




bool isPowerOfX(ll x, ll value)
{
    if(value==1)
        return true;
    while(value)
    {
        value/=x;
        if(value%x && value!=1)
            return false;
    }
    return true;
}
vector<ll>graph[333333];
bool visit[333333];
bool exist[333333];


void bfs(int src)
{
	queue<ll>q;
	q.push(src);
	while(!q.empty())
	{
		ll tmp = q.front();
		q.pop();
		visit[tmp] = true;
		for(auto x:graph[tmp])
		{
			if(visit[x])
				continue;
			q.push(x);
		}
	}
}



int main()
{
    fast;
    int n,m,x,y;
    cin>>n>>m;
    rep(i,m)cin>>x>>y,graph[x].pb(y),graph[y].pb(x),exist[x] = true,exist[y] = true;
    int cnt = 0;
    for(int i=1;i<=n;i++)
    {
		if(!visit[i] && exist[i])
			bfs(i),cnt++;
	}
	
		ll ans = cnt;
		if(cnt==1)
			ans = n;
		cout<<ans<<endl;
    return 0;
}



Compiler output:
a.cc: In function 'void bfs(int)':
a.cc:117:17: error: reference to 'visit' is ambiguous
  117 |                 visit[tmp] = true;
      |                 ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:8:
/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:105:6: note:                 'bool visit [333333]'
  105 | bool visit[333333];
      |      ^~~~~
a.cc:120:28: error: reference to 'visit' is ambiguous
  120 |                         if(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:105:6: note:                 'bool visit [333333]'
  105 | bool visit[333333];
      |      ^~~~~
a.cc: In function 'int main()':
a.cc:138:21: error: reference to 'visit' is ambiguous
  138 |                 if(!visit[i] && exist[i])
      |                     ^~~~~
/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:105:6: note:                 'bool visit [333333]'
  105 | bool visit[333333];
      |      ^~~~~