Problem p02678 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9 + 10;
const ll mod = 998244353;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define print(x) cerr << #x << " is " << x << endl;
// #define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << "
// " << __FILE__ << endl;
int V, E;
const int MAX_V = 200009;
using DD = int;
#define INF 1e9 + 7
DD d[MAX_V];
struct edge {
  int to;
  DD cost;
};
vector<edge> G[MAX_V];

int pprev[MAX_V];

void add_edge(int from, int to, DD dist) {
  G[from].push_back((edge){to, dist});
}
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  fill(pprev, pprev + V, -1);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
        pprev[e.to] = v;
      }
    }
  }
}
vector<int> get_path(int t) {
  vector<int> path;
  for (; t != -1; t = pprev[t])
    path.push_back(t);
  reverse(ALL(path));
  return path;
}

int main() {
  cin >> V >> E;
  rep(i, E) {
    int a, b;
    cin >> a >> b;
    add_edge(a - 1, b - 1, 1);
    add_edge(b - 1, a - 1, 1);
  }
  int s = 0;

  dijkstra(s); // O(M log N)

  rep(i, V) {
    // cout << i << " " << d[i] << endl;
    if (d[i] == INF) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes" << endl;
  reps(i, 1, V) { cout << pprev[i] + 1 << endl; }

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9 + 10;
const ll mod = 998244353;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
#define print(x) cerr << #x << " is " << x << endl;
// #define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << "
// " << __FILE__ << endl;
int V, E;
const int MAX_V = 1000;
using DD = int;
#define INF 1e9 + 7
DD d[MAX_V];
struct edge {
  int to;
  DD cost;
};
vector<edge> G[MAX_V];

int pprev[MAX_V];

void add_edge(int from, int to, DD dist) {
  G[from].push_back((edge){to, dist});
}
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  fill(pprev, pprev + V, -1);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
        pprev[e.to] = v;
      }
    }
  }
}
vector<int> get_path(int t) {
  vector<int> path;
  for (; t != -1; t = pprev[t])
    path.push_back(t);
  reverse(ALL(path));
  return path;
}

int main() {
  cin >> V >> E;
  rep(i, E) {
    int a, b;
    cin >> a >> b;
    add_edge(a - 1, b - 1, 1);
    add_edge(b - 1, a - 1, 1);
  }
  int s = 0;

  dijkstra(s); // O(M log N)

  rep(i, V) {
    // cout << i << " " << d[i] << endl;
    if (d[i] == INF) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes" << endl;
  reps(i, 1, V) { cout << pprev[i] + 1 << endl; }

  return 0;
}