Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;
int n,m;
vector<int>adj[N];
bool visit[N];
int dist[N];
int pa[N];
queue<int>q;
void bfs(int x){
    visit[x]=true;
    pa[x] = -1;      
    dist[x]=0;
    q.push(x);
    while(!q.empty()){
        int s=q.front();
        q.pop(); 
        for(auto u : adj[s]){
            if(visit[u])
                continue;
            visit[u]=true;
            dist[u]=dist[s]+1;
            pa[u] = s;
            q.push(u);
        }

    }
    f(i,1,n+1){
        if(!visit[i]){
            cout << "No\n";
            exit(0);
        }
    }
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    int i,x,y;
    f(i,0,m){
        cin >> x >> y;
        adj[x].push_back(y);
        adj[y].push_back(x);  
    }
    bfs(1);
    cout << "Yes\n";
    f(i,2,n+1){
        cout << dist[i] << "\n";
    }
    
    
    return 0;
}
 

Compiler output:
a.cc: In function 'void bfs(long long int)':
a.cc:15:5: error: reference to 'visit' is ambiguous
   15 |     visit[x]=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:10:6: note:                 'bool visit [500010]'
   10 | bool visit[N];
      |      ^~~~~
a.cc:23:16: error: reference to 'visit' is ambiguous
   23 |             if(visit[u])
      |                ^~~~~
/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:10:6: note:                 'bool visit [500010]'
   10 | bool visit[N];
      |      ^~~~~
a.cc:25:13: error: reference to 'visit' is ambiguous
   25 |             visit[u]=true;
      |             ^~~~~
/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:10:6: note:                 'bool visit [500010]'
   10 | bool visit[N];
      |      ^~~~~
a.cc:33:13: error: reference to 'visit' is ambiguous
   33 |         if(!visit[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:10:6: note:                 'bool visit [500010]'
   10 | bool visit[N];
      |      ^~~~~