Language: C++

#include <bits/stdc++.h>

using namespace std;

bool operator< (const pair<int, int> a, const pair<int, int> b){return a.first < b.first;};
//pair の1つ目の要素に従って昇順に処理したい
bool operator> (const pair<int, int> a, const pair<int, int> b){return a.first > b.first;};
//pair の2つ目の要素に従って降順に処理したい
// bool operator< (const pair<int, int> a, const pair<int, int> b){return a.second < b.second;};
// //pair の2つ目の要素に従って昇順に処理したい
// bool operator> (const pair<int, int> a, const pair<int, int> b){return a.second > b.second;};

void dijkstra(int initial, vector<bool> &visit, vector<int> &D, vector<int> &mother, vector<vector<int>> A)
{

    D[initial] = 0;
    visit[initial] = 1;

    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int,int>>> S;

    pair<int, int> p = make_pair(D[initial], initial);

    S.push(p);

    while (!S.empty())
    {
        int w = S.front().second;

        S.pop();

        if (A[w].size() > 0)
        {
            for (int i = 0; i < A[w].size(); i++)
            {

                if (visit[A[w][i]] == 0)
                {
                    pair<int, int> new_pair = make_pair(D[A[w][i]], A[w][i]);
                    S.push(new_pair);
                    visit[A[w][i]] = 1;
                }

                if (D[w] + 1 < D[A[w][i]])
                {

                    D[A[w][i]] = D[w] + 1;

                    mother[A[w][i]] = w;
                }
            }
        }
    }
}

int main()
{

    const int INF = 1001001001

    int N, M;

    cin >> N >> M;

    //graph
    vector<vector<int>> A(N, vector<int>(0));

    // aint eady visit?
    vector<bool> visit(N, 0);

    // mother room of the room
    vector<int> mother(N);

    // cost array
    vector<int> D(N, INF);

    for (int i = 0; i < M; i++)
    {

        int b, c;

        cin >> b >> c;

        A[b - 1].push_back(c - 1);
        A[c - 1].push_back(b - 1);
    }
    //initialization
    dijkstra(0, visit, D, mother, A);
 

    for (int i = 0; i < N; i++)
    {
        if (visit[i] == 0)
        {
            cout <<"No"<< endl;
        }
    }
    

    cout << "Yes" << endl;
    for (int i = 1; i < N; i++)
    {

        cout << mother[i] + 1 << endl;
    }

    return 0;
}




// #include <bits/stdc++.h>
// #define rep(i,n) for (int i = 0; i < (n); ++i)
// using namespace std;
// using ll = long long;
// using P = pair<int,int>;
 
// const int INF = 1001001001;
// vector<int> to[100005];
 
// int main() {
//   int n, m;
//   cin >> n >> m;
//   rep(i,m) {
//     int a, b;
//     cin >> a >> b;
//     --a; --b;
//     to[a].push_back(b);
//     to[b].push_back(a);
//   }
 
//   queue<int> q;
//   vector<int> dist(n, INF);
//   vector<int> pre(n, -1);
//   dist[0] = 0;
//   q.push(0);
//   while (!q.empty()) {
//     int v = q.front(); q.pop();
//     for (int u : to[v]) {
//       if (dist[u] != INF) continue;
//       dist[u] = dist[v]+1;
//       pre[u] = v;
//       q.push(u);
//     }
//   }
 
//   cout << "Yes" << endl;
//   rep(i,n) {
//     if (i == 0) continue;
//     int ans = pre[i];
//     ++ans;
//     cout << ans << endl;
//   }
//   return 0;
// }




Compiler output:
a.cc: In function 'void dijkstra(int, std::vector<bool>&, std::vector<int>&, std::vector<int>&, std::vector<std::vector<int> >)':
a.cc:27:19: error: 'class std::priority_queue<std::pair<int, int>, std::vector<std::pair<int, int> >, std::greater<std::pair<int, int> > >' has no member named 'front'
   27 |         int w = S.front().second;
      |                   ^~~~~
a.cc: In function 'int main()':
a.cc:60:5: error: expected ',' or ';' before 'int'
   60 |     int N, M;
      |     ^~~
a.cc:62:12: error: 'N' was not declared in this scope
   62 |     cin >> N >> M;
      |            ^
a.cc:62:17: error: 'M' was not declared in this scope
   62 |     cin >> N >> M;
      |                 ^