Language: C++

#include <iostream>
#include <vector>
using namespace std;

typedef struct {
    uint32_t number;
    vector<uint32_t> aisle;
    uint32_t ans;
    uint32_t count;
}Doukutsu;

void michishirube(Doukutsu *d, uint32_t idx, uint32_t count)
{
    for (uint32_t i : d[idx].aisle) {
        if (i != 0  &&
            count < d[i].count) {
            d[i].ans = idx + 1;
            d[i].count = count;
            michishirube(d, i, count+1);
        }
    }
}

int main(int argc, const char * argv[]) {
    uint32_t N, M;
    cin >> N >> M;
    
    Doukutsu *d = new Doukutsu[N];
    // init
    for (uint32_t i = 0; i < N; i++) {
        d[i].number = i;
        d[i].ans = 0;
        d[i].count = UINT_MAX;
    }
    
    for (uint32_t i = 0; i < M; i++) {
        uint32_t A, B;
        cin >> A >> B;
        uint32_t a = A - 1;
        uint32_t b = B - 1;
        
        d[a].aisle.push_back(b);
        d[b].aisle.push_back(a);
    }
    
    michishirube(d, 0, 0);
    
    // check
    bool no = false;
    for (uint32_t i = 1; i < N; i++) {
        if (d[i].ans == 0) {
            no = true;
            break;
        }
    }
    
    if (no) {
        cout << "No";
    }else {
        cout << "Yes" << endl;
        for (uint32_t i = 1; i < N; i++) {
            cout << d[i].ans << endl;
        }
    }
    
    delete[] d;
    return 0;
}

Compiler output:
a.cc:6:5: error: 'uint32_t' does not name a type
    6 |     uint32_t number;
      |     ^~~~~~~~
a.cc:3:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    2 | #include <vector>
  +++ |+#include <cstdint>
    3 | using namespace std;
a.cc:7:12: error: 'uint32_t' was not declared in this scope
    7 |     vector<uint32_t> aisle;
      |            ^~~~~~~~
a.cc:7:12: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:7:20: error: template argument 1 is invalid
    7 |     vector<uint32_t> aisle;
      |                    ^
a.cc:7:20: error: template argument 2 is invalid
a.cc:8:5: error: 'uint32_t' does not name a type
    8 |     uint32_t ans;
      |     ^~~~~~~~
a.cc:8:5: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:9:5: error: 'uint32_t' does not name a type
    9 |     uint32_t count;
      |     ^~~~~~~~
a.cc:9:5: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:12:32: error: 'uint32_t' has not been declared
   12 | void michishirube(Doukutsu *d, uint32_t idx, uint32_t count)
      |                                ^~~~~~~~
a.cc:12:46: error: 'uint32_t' has not been declared
   12 | void michishirube(Doukutsu *d, uint32_t idx, uint32_t count)
      |                                              ^~~~~~~~
a.cc: In function 'void michishirube(Doukutsu*, int, int)':
a.cc:14:10: error: 'uint32_t' was not declared in this scope
   14 |     for (uint32_t i : d[idx].aisle) {
      |          ^~~~~~~~
a.cc:14:10: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:22:1: error: expected primary-expression before '}' token
   22 | }
      | ^
a.cc:21:6: error: expected ';' before '}' token
   21 |     }
      |      ^
      |      ;
   22 | }
      | ~     
a.cc:22:1: error: expected primary-expression before '}' token
   22 | }
      | ^
a.cc:21:6: error: expected ')' before '}' token
   21 |     }
      |      ^
      |      )
   22 | }
      | ~     
a.cc:14:9: note: to match this '('
   14 |     for (uint32_t i : d[idx].aisle) {
      |         ^
a.cc:22:1: error: expected primary-expression before '}' token
   22 | }
      | ^
a.cc: In function 'int main(int, const char**)':
a.cc:25:5: error: 'uint32_t' was not declared in this scope
   25 |     uint32_t N, M;
      |     ^~~~~~~~
a.cc:25:5: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
a.cc:26:12: error: 'N' was not declared in this scope
   26 |     cin >> N >> M;
      |            ^
a.cc:26:17: error: 'M' was not declared in this scope
   26 |     cin >> N >> M;
      |                 ^
a.cc:30:18: error: expected ';' before 'i'
   30 |     for (uint32_t i = 0; i < N; i++) {
      |                  ^~
      |                  ;
a.cc:30:26: error: 'i' was not declared in this scope
   30 |     for (uint32_t i = 0; i < N; i++) {
      |                          ^
a.cc:33:22: error: 'UINT_MAX' was not declared in this scope
   33 |         d[i].count = UINT_MAX;
      |                      ^~~~~~~~
a.cc:3:1: note: 'UINT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
    2 | #include <vector>
  +++ |+#include <climits>
    3 | using namespace std;
a.cc:36:18: error: expected ';' before 'i'
   36 |     for (uint32_t i = 0; i < M; i++) {
      |                  ^~
      |                  ;
a.cc:36:26: error: 'i' was not declared in this scope
   36 |     for (uint32_t i = 0; i < M; i++) {
      |                          ^
a.cc:37:17: error: expected ';' before 'A'
   37 |         uint32_t A, B;
      |                 ^~
      |                 ;
a.cc:38:16: error: 'A' was not declared in this scope
   38 |         cin >> A >> B;
      |                ^
a.cc:38:21: error: 'B' was not declared in this scope
   38 |         cin >> A >> B;
      |                     ^
a.cc:39:17: error: expected ';' before 'a'
   39 |         uint32_t a = A - 1;
      |                 ^~
      |                 ;
a.cc:40:17: error: expected ';' before 'b'
   40 |         uint32_t b = B - 1;
      |                 ^~
      |                 ;
a.cc:42:11: error: 'a' was not declared in this scope
   42 |         d[a].aisle.push_back(b);
      |           ^
a.cc:42:30: error: 'b' was not declared in this scope
   42 |         d[a].aisle.push_back(b);
      |                              ^
a.cc:50:18: error: expected ';' before 'i'
   50 |     for (uint32_t i = 1; i < N; i++) {
      |                  ^~
      |                  ;
a.cc:50:26: error: 'i' was not declared in this scope
   50 |     for (uint32_t i = 1; i < N; i++) {
      |                          ^
a.cc:61:22: error: expected ';' before 'i'
   61 |         for (uint32_t i = 1; i < N; i++) {
      |                      ^~
      |                      ;
a.cc:61:30: error: 'i' was not declared in this scope
   61 |         for (uint32_t i = 1; i < N; i++) {
      |                              ^