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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
using namespace std;
int n, m, d[100005], tot;
vector<int> a[100005];
void bfs();
queue<int> q;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[x].push_back(y);
    a[y].push_back(x);
  }
  bfs();
  return 0;
}
void bfs() {
  d[1] = 1;
  q.push(1);
  while (!q.empty() && tot < n) {
    int tmp = q.front();
    q.pop();
    ++tot;
    for (int i = 0; i < (int)a[tmp].size(); ++i) {
      if (d[a[tmp][i]] != 0)
        continue;
      d[a[tmp][i]] = tmp;
      q.push(a[tmp][i]);
    }
  }
  if (tot == n) {
    cout << "Yes\\n";
    for (int i = 2; i <= n; ++i)
      printf("%d\\n", d[i]);
    return;
  } else
    cout << "No";
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
using namespace std;
int n, m, d[10005], tot;
vector<int> a[10005];
void bfs();
queue<int> q;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    a[x].push_back(y);
    a[y].push_back(x);
  }
  bfs();
  return 0;
}
void bfs() {
  d[1] = 1;
  q.push(1);
  while (!q.empty() && tot < n) {
    int tmp = q.front();
    q.pop();
    ++tot;
    for (int i = 0; i < (int)a[tmp].size(); ++i) {
      if (d[a[tmp][i]] != 0)
        continue;
      d[a[tmp][i]] = tmp;
      q.push(a[tmp][i]);
    }
  }
  if (tot == n) {
    cout << "Yes\\n";
    for (int i = 2; i <= n; ++i)
      printf("%d\\n", d[i]);
    return;
  } else
    cout << "No";
}