Problem p02678 (C++)

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

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>

#define INF 1e9
#define INFL 8e18
#define XX first
#define YY second
#define PB push_back
#define MP make_pair

#define NEWLINE cerr << "\n";
#define HOISE cerr << "hoise " << __LINE__ << "\n"
#define PAUSE system("pause")
#define DEBUG(x) cerr << #x << " = " << x << "\n"
#define READ freopen("D:\\moidda CPP\\alu.txt", "r", stdin)
#define WRITE freopen("D:\\moidda CPP\\vorta.txt", "w", stdout)
#define FASTIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define MASK(x)                                                                \
  for (int i = 0; i < 8; i++) {                                                \
    if (x & (1 << i)) {                                                        \
      cout << i << " ";                                                        \
    }                                                                          \
  }                                                                            \
  cout << endl;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pff;

const int MAX = 30 + 10;
const int MAX_VALUE = 2e6 + 10;
const int MAXLOG = log2(MAX) + 2;
const int MOD = 10007;
const double PY = acos(-1.0);
const double EPS = 1E-9;

int n, m;
vector<int> G[MAX];
int dis[MAX];
int par[MAX];

int32_t main() {
#ifndef ONLINE_JUDGE
//    READ;
//    WRITE;
#endif

  FASTIO;

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    G[u].PB(v);
    G[v].PB(u);
  }

  for (int i = 0; i < MAX; i++)
    dis[i] = INF;
  memset(par, -1, sizeof par);

  queue<int> Q;
  dis[1] = 0;
  Q.push(1);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int v : G[u]) {
      if (dis[v] > dis[u] + 1) {
        dis[v] = dis[u] + 1;
        par[v] = u;
        Q.push(v);
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    if (dis[i] >= INF) {
      cout << "No";
      return 0;
    }
  }

  cout << "Yes\n";
  for (int i = 2; i <= n; i++)
    cout << par[i] << "\n";

  return 0;
}


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

#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>,
// rb_tree_tag,tree_order_statistics_node_update>

#define INF 1e9
#define INFL 8e18
#define XX first
#define YY second
#define PB push_back
#define MP make_pair

#define NEWLINE cerr << "\n";
#define HOISE cerr << "hoise " << __LINE__ << "\n"
#define PAUSE system("pause")
#define DEBUG(x) cerr << #x << " = " << x << "\n"
#define READ freopen("D:\\moidda CPP\\alu.txt", "r", stdin)
#define WRITE freopen("D:\\moidda CPP\\vorta.txt", "w", stdout)
#define FASTIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define MASK(x)                                                                \
  for (int i = 0; i < 8; i++) {                                                \
    if (x & (1 << i)) {                                                        \
      cout << i << " ";                                                        \
    }                                                                          \
  }                                                                            \
  cout << endl;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pff;

const int MAX = 1e5 + 10;
const int MAX_VALUE = 2e6 + 10;
const int MAXLOG = log2(MAX) + 2;
const int MOD = 10007;
const double PY = acos(-1.0);
const double EPS = 1E-9;

int n, m;
vector<int> G[MAX];
int dis[MAX];
int par[MAX];

int32_t main() {
#ifndef ONLINE_JUDGE
//    READ;
//    WRITE;
#endif

  FASTIO;

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    G[u].PB(v);
    G[v].PB(u);
  }

  for (int i = 0; i < MAX; i++)
    dis[i] = INF;
  memset(par, -1, sizeof par);

  queue<int> Q;
  dis[1] = 0;
  Q.push(1);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int v : G[u]) {
      if (dis[v] > dis[u] + 1) {
        dis[v] = dis[u] + 1;
        par[v] = u;
        Q.push(v);
      }
    }
  }

  for (int i = 1; i <= n; i++) {
    if (dis[i] >= INF) {
      cout << "No";
      return 0;
    }
  }

  cout << "Yes\n";
  for (int i = 2; i <= n; i++)
    cout << par[i] << "\n";

  return 0;
}