Language: C++

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

int n, m;
//vector<vector<int>> x(n, vector<int>(m));
//vector<int> dat(n);

void pei(int a, vector<vector<int>&>& x, vector<int>& dat){
  int i, j;
  vector<int> y(1, 0);
  for(i = 1; i < n; i++){
    if(x[a-1][i] == 1){
      y.push_back(i+1);
      dat[i] = a;
      for(j = 0; j < n; j++){
        x[j][i] = 0;
      }
    }
  }
  int s = y.size();
  if(s == 1){
    return;
  }else{
  	for(i = 1; i < s; i++){
      pei(y[i], x, dat);
  	}
  }
}

int main(){
  int i;
  cin >> n >> m;
  vector<vector<int>> x(n, vector<int>(n, 0));
  vector<int> dat(n, 0);
  for(i = 0; i < m; i++){
    int a, b;
    cin >> a >> b;
    x[a-1][b-1] = 1;
    x[b-1][a-1] = 1;
  }
  pei(1, x, dat);
  for(i = 1; i < n; i++){
    if(dat[i] == 0){
      break;
    }
  }
  if(i < n){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
    for(i = 1; i < n; i++){
      cout << dat[i] << endl;
    }
  }
  return 0;
}


Compiler output:
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/string:43,
                 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/new_allocator.h: In instantiation of 'class std::__new_allocator<std::vector<int>&>':
/usr/include/c++/14/bits/allocator.h:128:11:   required from 'class std::allocator<std::vector<int>&>'
  128 |     class allocator : public __allocator_base<_Tp>
      |           ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:87:21:   required from 'struct std::_Vector_base<std::vector<int>&, std::allocator<std::vector<int>&> >'
   87 |         rebind<_Tp>::other _Tp_alloc_type;
      |                            ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:428:11:   required from 'class std::vector<std::vector<int>&>'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
a.cc:12:13:   required from here
   12 |     if(x[a-1][i] == 1){
      |             ^
/usr/include/c++/14/bits/new_allocator.h:70:26: error: forming pointer to reference type 'std::vector<int>&'
   70 |       typedef _Tp*       pointer;
      |                          ^~~~~~~
/usr/include/c++/14/bits/new_allocator.h:71:26: error: forming pointer to reference type 'std::vector<int>&'
   71 |       typedef const _Tp* const_pointer;
      |                          ^~~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:126:7: error: forming pointer to reference type 'std::vector<int>&'
  126 |       allocate(size_type __n, const void* = static_cast<const void*>(0))
      |       ^~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:156:7: error: forming pointer to reference type 'std::vector<int>&'
  156 |       deallocate(_Tp* __p, size_type __n __attribute__ ((__unused__)))
      |       ^~~~~~~~~~
/usr/include/c++/14/bits/allocator.h: In instantiation of 'class std::allocator<std::vector<int>&>':
/usr/include/c++/14/bits/stl_vector.h:87:21:   required from 'struct std::_Vector_base<std::vector<int>&, std::allocator<std::vector<int>&> >'
   87 |         rebind<_Tp>::other _Tp_alloc_type;
      |                            ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:428:11:   required from 'class std::vector<std::vector<int>&>'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
a.cc:12:13:   required from here
   12 |     if(x[a-1][i] == 1){
      |             ^
/usr/include/c++/14/bits/allocator.h:137:26: error: forming pointer to reference type 'std::vector<int>&'
  137 |       typedef _Tp*       pointer;
      |                          ^~~~~~~
/usr/include/c++/14/bits/allocator.h:138:26: error: forming pointer to reference type 'std::vector<int>&'
  138 |       typedef const _Tp* const_pointer;
      |                          ^~~~~~~~~~~~~
In file included from /usr/include/c++/14/ext/alloc_traits.h:34,
                 from /usr/include/c++/14/bits/basic_string.h:39,
                 from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/alloc_traits.h: In instantiation of 'struct std::allocator_traits<std::allocator<std::vector<int>&> >':
/usr/include/c++/14/ext/alloc_traits.h:45:10:   required from 'struct __gnu_cxx::__alloc_traits<std::allocator<std::vector<int>&>, std::vector<int>&>'
   45 |   struct __alloc_traits
      |          ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:87:21:   required from 'struct std::_Vector_base<std::vector<int>&, std::allocator<std::vector<int>&> >'
   87 |         rebind<_Tp>::other _Tp_alloc_type;
      |                            ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:428:11:   required from 'class std::vector<std::vector<int>&>'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
a.cc:12:13:   required from here
   12 |     if(x[a-1][i] == 1){
      |             ^
/usr/include/c++/14/bits/alloc_traits.h:470:13: error: forming pointer to reference type 'std::vector<int>&'
  470 |       using pointer = _Tp*;
      |             ^~~~~~~
/usr/include/c++/14/bits/alloc_traits.h:473:13: error: forming pointer to reference type 'std::vector<int>&'
  473 |       using const_pointer = const _Tp*;
      |             ^~~~~~~~~~~~~
/usr/include/c++/14/ext/alloc_traits.h: In instantiation of 'struct __gnu_cxx::__alloc_traits<std::allocator<std::vector<int>&>, std::vector<int>&>':
/usr/include/c++/14/bits/stl_vector.h:87:21:   required from 'struct std::_Vector_base<std::vector<int>&, std::allocator<std::vector<int>&> >'
   87 |         rebind<_Tp>::other _Tp_alloc_type;
      |                            ^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:428:11:   required from 'class std::vector<std::vector<int>&>'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
a.cc:12:13:   required from here
   12 |     if(x[a-1][i] == 1){
      |             ^
/usr/include/c++/14/ext/alloc_traits.h:61:23: error: 'allocate' has not been declared in '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int>&>, std::vector<int>&>::_Base_type'
   61 |     using _Base_type::allocate;
      |                       ^~~~~~~~
/usr/include/c++/14/ext/alloc_traits.h:62:23: error: 'deallocate' has not been declared in '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int>&>, std::vector<int>&>::_Base_type'
   62 |     using _Base_type::deallocate;
      |                       ^~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h: In instantiation of 'class std::vector<std::vector<int>&>':
a.cc:12:13:   required from here
   12 |     if(x[a-1][i] == 1){
      |             ^
/usr/include/c++/14/bits/stl_vector.h:518:20: error: '_M_allocate' has not been declared in 'std::vector<std::vector<int>&>::_Base'
  518 |       using _Base::_M_allocate;
      |                    ^~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:519:20: error: '_M_deallocate' has not been declared in 'std::vector<std::vector<int>&>::_Base'
  519 |       using _Base::_M_deallocate;
      |                    ^~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1262:7: error: forming pointer to reference type 'std::vector<int>&'
 1262 |       data() _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_vector.h:1267:7: error: forming pointer to reference type 'std::vector<int>&'
 1267 |       data() const _GLIBCXX_NOEXCEPT
      |       ^~~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: error: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::vector<int>&; _Alloc = std::allocator<std::vector<int>&>; value_type = std::vector<int>&]' cannot be overloaded with 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<int>&; _Alloc = std::allocator<std::vector<int>&>; value_type = std::vector<int>&]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: previous declaration 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<int>&; _Alloc = std::allocator<std::vector<int>&>; value_type = std::vector<int>&]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
a.cc: In function 'int main()':
a.cc:41:10: error: invalid initialization of reference of type 'std::vector<std::vector<int>&>&' from expression of type 'std::vector<std::vector<int> >'
   41 |   pei(1, x, dat);
      |          ^
a.cc:8:39: note: in passing argument 2 of 'void pei(int, std::vector<std::vector<int>&>&, std::vector<int>&)'
    8 | void pei(int a, vector<vector<int>&>& x, vector<int>& dat){
      |                 ~~~~~~~~~~~~~~~~~~~~~~^