Language: C++

#include <iostream>
#include <cstdlib>
#include <vector>
#include <queue>

int main() {
    int32_t n, m;
    std::cin >> n >> m;

    std::vector<std::vector<bool>> links(n);
    for (int32_t i = 0; i < n; ++i) {
        links[i].resize(n);
    }
    for (int32_t i = 0; i < m; ++i) {
        int32_t a, b;
        std::cin >> a >> b;
        links[a - 1][b - 1] = true;
        links[b - 1][a - 1] = true;
    }


    std::vector<int32_t> rec(n, std::numeric_limits<int32_t>::max());
    rec[0] = 0;

    using P = std::pair<int32_t, int32_t>;
    std::priority_queue<P> queue;
    
    queue.push(P(0, 0));
    while(!queue.empty()) {
        const auto& top = queue.top();
        int32_t cost = top.first;
        int32_t index = top.second;
        queue.pop();

        for (int32_t i = 0; i < n; ++i) {
            if (!links[index][i]) {
                continue;
            }
            auto dist = cost + 1;
            
            if (dist < rec[i]) {
                rec[i] = dist;
                queue.push(P(dist, i));
            }
        }
    }

    auto ng = std::any_of(rec.begin(), rec.end(),[](int32_t r){
        return r == std::numeric_limits<int32_t>::max();
    });
    

    if (ng) {
        std::cout << "No" << std::endl;
        return 0;
    }
    
    std::cout << "Yes" << std::endl;    
    for (auto i = 1; i < n; ++i) {
        std::cout << rec[i] << std::endl;
    }
    
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:22:38: error: 'numeric_limits' is not a member of 'std'
   22 |     std::vector<int32_t> rec(n, std::numeric_limits<int32_t>::max());
      |                                      ^~~~~~~~~~~~~~
a.cc:22:60: error: expected primary-expression before '>' token
   22 |     std::vector<int32_t> rec(n, std::numeric_limits<int32_t>::max());
      |                                                            ^
a.cc:22:63: error: '::max' has not been declared; did you mean 'std::max'?
   22 |     std::vector<int32_t> rec(n, std::numeric_limits<int32_t>::max());
      |                                                               ^~~
      |                                                               std::max
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: 'std::max' declared here
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
a.cc:48:20: error: 'any_of' is not a member of 'std'
   48 |     auto ng = std::any_of(rec.begin(), rec.end(),[](int32_t r){
      |                    ^~~~~~
a.cc: In lambda function:
a.cc:49:26: error: 'numeric_limits' is not a member of 'std'
   49 |         return r == std::numeric_limits<int32_t>::max();
      |                          ^~~~~~~~~~~~~~
a.cc:49:48: error: expected primary-expression before '>' token
   49 |         return r == std::numeric_limits<int32_t>::max();
      |                                                ^
a.cc:49:51: error: '::max' has not been declared; did you mean 'std::max'?
   49 |         return r == std::numeric_limits<int32_t>::max();
      |                                                   ^~~
      |                                                   std::max
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: 'std::max' declared here
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~