Language: C++

#include<bits/stdc++.h>
using namespace std;

vector<int> v[10001];
vector<int> visit(10001,-1);

void bfs(){
  int s = 1;
  visit[s]=0;
  queue<int> q;
  q.push(s);
  while(!q.empty()){
    int t = q.front();
    q.pop();
    for(int i=0; i<v[t].size(); i++){
      if(visit[v[t][i]]==-1){
        q.push(v[t][i]);
        visit[v[t][i]]=t;
      }
    }
  }
  return;
}

int main(){
  int N, M;
  cin >> N >> M;
  for(int i=0; i<M; i++){
    int A, B;
    cin >> A >> B;
    v[A].push_back(B);
    v[B].push_back(A);
  }
  bfs();
  for(int i=2; i<=N; i++){
    if(visit[i]==-1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  for(int i=2; i<=N; i++){
    cout << visit[i] << endl;
  }
  return 0;
}


Compiler output:
a.cc: In function 'void bfs()':
a.cc:9:3: error: reference to 'visit' is ambiguous
    9 |   visit[s]=0;
      |   ^~~~~
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:5:13: note:                 'std::vector<int> visit'
    5 | vector<int> visit(10001,-1);
      |             ^~~~~
a.cc:16:10: error: reference to 'visit' is ambiguous
   16 |       if(visit[v[t][i]]==-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:5:13: note:                 'std::vector<int> visit'
    5 | vector<int> visit(10001,-1);
      |             ^~~~~
a.cc:18:9: error: reference to 'visit' is ambiguous
   18 |         visit[v[t][i]]=t;
      |         ^~~~~
/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:5:13: note:                 'std::vector<int> visit'
    5 | vector<int> visit(10001,-1);
      |             ^~~~~
a.cc: In function 'int main()':
a.cc:36:8: error: reference to 'visit' is ambiguous
   36 |     if(visit[i]==-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:5:13: note:                 'std::vector<int> visit'
    5 | vector<int> visit(10001,-1);
      |             ^~~~~
a.cc:43:13: error: reference to 'visit' is ambiguous
   43 |     cout << visit[i] << endl;
      |             ^~~~~
/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:5:13: note:                 'std::vector<int> visit'
    5 | vector<int> visit(10001,-1);
      |             ^~~~~