Problem p02678 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#ifdef _PRINTDEBUG
#include "lib/printdebug.hpp"
#else
#define printdebug(...) 1
#endif
#define I_1000000007 (1000000007)
#define I_998244353 (998244353)
#define I_INF (1 << 28)
#define L_INF (1LL << 60)
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond) YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}

namespace solver {
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int N, M, parent[100010];
Graph G;

void init() {
  cin >> N >> M;
  G.resize(N);
  int a, b;
  rep(i, N) {
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
}

void bfs() {
  queue<pair<int, int>> que;
  que.push(make_pair(0, 0));
  while (!que.empty()) {
    auto pr = que.front();
    que.pop();
    int s = pr.first, p = pr.second;
    if (parent[s] >= 0)
      continue;
    parent[s] = p;
    for (const auto &t : G[s]) {
      if (parent[t] >= 0)
        continue;
      else {
        que.push(make_pair(t, s));
      }
    }
  }
}

void solve() {
  memset(parent, -1, sizeof parent);
  bfs();
  cout << "Yes"
       << "\n";
  REP(i, 1, N) { cout << parent[i] + 1 << "\n"; }
}
} // namespace solver

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#ifdef _PRINTDEBUG
#include "lib/printdebug.hpp"
#else
#define printdebug(...) 1
#endif
#define I_1000000007 (1000000007)
#define I_998244353 (998244353)
#define I_INF (1 << 28)
#define L_INF (1LL << 60)
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond) YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"
template <class T> inline bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T> inline bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}

namespace solver {
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int N, M, parent[100010];
Graph G;

void init() {
  cin >> N >> M;
  G.resize(N);
  int a, b;
  rep(i, M) {
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
}

void bfs() {
  queue<pair<int, int>> que;
  que.push(make_pair(0, 0));
  while (!que.empty()) {
    auto pr = que.front();
    que.pop();
    int s = pr.first, p = pr.second;
    if (parent[s] >= 0)
      continue;
    parent[s] = p;
    for (const auto &t : G[s]) {
      if (parent[t] >= 0)
        continue;
      else {
        que.push(make_pair(t, s));
      }
    }
  }
}

void solve() {
  memset(parent, -1, sizeof parent);
  bfs();
  cout << "Yes"
       << "\n";
  REP(i, 1, N) { cout << parent[i] + 1 << "\n"; }
}
} // namespace solver

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}