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

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

#define ris return *this
#define tmplt template <class T
#define dbgo debug &operator<<
tmplt > struct rge {
  T b, e;
};
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  tmplt > dbgo(T x) {
    cerr << boolalpha << x;
    ris;
  }
  tmplt, class C > dbgo(pair<T, C> x) {
    ris << "(" << x.first << ", " << x.second << ")";
  }
  tmplt > dbgo(rge<T> x) {
    *this << "[";
    for (auto it = x.b; it != x.e; it++) {
      *this << ", " + 2 * (it == x.b) << *it;
    }
    ris << "]";
  }
  tmplt > dbgo(vector<T> x) { ris << range(x.begin(), x.end()); }
#else
  tmplt > dbgo(const T &) { ris; }
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)

template <typename T> void min_self(T &a, T b) { a = min(a, b); }
template <typename T> void max_self(T &a, T b) { a = max(a, b); }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  forn(i, m) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> par(n, -1);
  vector<int> q{0};
  par[0] = 0;
  forn(i, q.size()) {
    int u = q[i];
    for (int v : g[u]) {
      if (par[v] == -1) {
        par[v] = u;
        q.push_back(v);
      }
    }
  }
  cout << "Yes\\n";
  for (int i = 1; i < n; i++) {
    cout << par[i] + 1 << '\\n';
  }
}

// Don't worry, you're getting better

// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)

// Author: blondie


Error: 0

Fixed submission:

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

#define ris return *this
#define tmplt template <class T
#define dbgo debug &operator<<
tmplt > struct rge {
  T b, e;
};
tmplt > rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  tmplt > dbgo(T x) {
    cerr << boolalpha << x;
    ris;
  }
  tmplt, class C > dbgo(pair<T, C> x) {
    ris << "(" << x.first << ", " << x.second << ")";
  }
  tmplt > dbgo(rge<T> x) {
    *this << "[";
    for (auto it = x.b; it != x.e; it++) {
      *this << ", " + 2 * (it == x.b) << *it;
    }
    ris << "]";
  }
  tmplt > dbgo(vector<T> x) { ris << range(x.begin(), x.end()); }
#else
  tmplt > dbgo(const T &) { ris; }
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ford(i, n) for (int i = n - 1; i >= 0; i--)

template <typename T> void min_self(T &a, T b) { a = min(a, b); }
template <typename T> void max_self(T &a, T b) { a = max(a, b); }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  forn(i, n) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  vector<int> par(n, -1);
  vector<int> q{0};
  par[0] = 0;
  forn(i, q.size()) {
    int u = q[i];
    for (int v : g[u]) {
      if (par[v] == -1) {
        par[v] = u;
        q.push_back(v);
      }
    }
  }
  cout << "Yes\\n";
  for (int i = 1; i < n; i++) {
    cout << par[i] + 1 << '\\n';
  }
}

// Don't worry, you're getting better

// Read statement carefully
// Solve on paper first!
// Make your infinity big enough
// Overflows (long long)

// Author: blondie