Language: C++

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i=0; i<(int64_t)(n); i++)
#define all(v) v.begin(), v.end()
//d
vector< bool > check(100000);
vector< vector< int > > data(100000, vector< int > (0));
vector< int > ans(100000);
queue< int > qA, qB;

void dfs(int i, int j){
  
  if(check[i-1]) return;
  else check[i-1] = true;
  ans[i-1]=j;
  for(int x: data[i-1]){
    qA.push(x);
    qB.push(i);
  }
  return;
  
}

void search(){
  
  qA.push(1);
  qB.push(-1);
  while(qA.size()!=0){
    dfs(qA.front(), qB.front());
    qA.pop();
    qB.pop();
  }
  return;
  
}

int main(){
  
  int N, M; cin >> N >> M;
  cout << "Yes" << endl;
  rep(i, M){
    int a, b; cin >> a >> b;
    data[a-1].push_back(b);
    data[b-1].push_back(a);
  }
  
  search();
  
  rep(i, N) if(i!=0) cout << ans[i] << endl;
  
}

Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:16:14: error: reference to 'data' is ambiguous
   16 |   for(int x: data[i-1]){
      |              ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:25: note:                 'std::vector<std::vector<int> > data'
    7 | vector< vector< int > > data(100000, vector< int > (0));
      |                         ^~~~
a.cc: In function 'int main()':
a.cc:43:5: error: reference to 'data' is ambiguous
   43 |     data[a-1].push_back(b);
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:25: note:                 'std::vector<std::vector<int> > data'
    7 | vector< vector< int > > data(100000, vector< int > (0));
      |                         ^~~~
a.cc:44:5: error: reference to 'data' is ambiguous
   44 |     data[b-1].push_back(a);
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:7:25: note:                 'std::vector<std::vector<int> > data'
    7 | vector< vector< int > > data(100000, vector< int > (0));
      |                         ^~~~