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

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<ll, ll> P;
const int mod = 1e9 + 7;

struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint &operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    (x -= mod - a.x) %= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t % 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    fact[0] = 1;
    for (int i = 1; i < n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] + ifact[n - k];
  }
};

vector<vector<int>> A(200000, vector<int>());

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    A[a].push_back(b);
    A[b].push_back(a);
  }

  vector<ll> dist(n, INF);
  queue<int> q;
  auto push = [&](int v, int d) {
    if (dist[v] != INF)
      return;
    dist[v] = d;
    q.push(v);
  };
  push(0, 0);
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    rep(i, A[t].size()) { push(A[t][i], t); }
  }
  cout << "Yes" << endl;
  rrep(i, n - 1) { cout << dist[i] + 1 << endl; }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<ll, ll> P;
const int mod = 1e9 + 7;

struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint &operator+=(const mint a) {
    (x += a.x) %= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    (x -= mod - a.x) %= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t % 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    fact[0] = 1;
    for (int i = 1; i < n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] + ifact[n - k];
  }
};

vector<vector<int>> A(10000 + 50, vector<int>());

// void bfs(int i, int p){
//     if(C[i]!=-1)return;
//     rep(j,A[i].size()){
//         bfs(A[i][j],i);
//     }
//     C[i] = p;
// }

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    A[a].push_back(b);
    A[b].push_back(a);
  }

  vector<ll> dist(n, INF);
  queue<int> q;
  auto push = [&](int v, int d) {
    if (dist[v] != INF)
      return;
    dist[v] = d;
    q.push(v);
  };
  push(0, 0);
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    rep(i, A[t].size()) { push(A[t][i], t); }
  }
  cout << "Yes" << endl;
  rrep(i, n - 1) { cout << dist[i] + 1 << endl; }
  return 0;
}