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

#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<ll, ll> ii;

#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define endl "\\n"
#define fx(n) fixed << setprecision(n)
#define mk make_pair

void File() {
#ifndef ONLINE_JUDGE
  freopen("output.txt", "w", stdout);
  freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
  /*freopen("output.txt", "w", stdout);
  freopen("commandos.in", "r", stdin);*/
#endif
}
void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
  // File();
}
const double pi = acos(-1.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 2e5 + 15;
int dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

int n, m;
vector<int> gr[nn];
int vis[nn];
void BFS(int S) {
  vector<int> dis(nn, oo);
  vector<int> per(nn, 0);
  queue<pair<int, int>> qq;
  qq.push(make_pair(S, 0));
  dis[S] = 0;
  while (!qq.empty()) {
    pair<int, int> cur = qq.front();
    qq.pop();
    for (auto it : gr[cur.first]) {
      if (dis[it] > dis[cur.first] + 1) {
        dis[it] = dis[cur.first] + 1;
        per[it] = cur.first;
        qq.push(make_pair(it, dis[it]));
      }
    }
  }
  bool f = 0;
  for (int i = 2; i <= n && !f; i++) {
    if (dis[i] == oo)
      f = 1;
  }
  if (f)
    cout << "No\\n";
  else {
    cout << "Yes\\n";
    for (int i = 2; i <= n; i++)
      cout << per[i] << endl;
  }
}
int main() {
  fast();
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    gr[u].push_back(v);
    gr[v].push_back(u);
  }
  BFS(1);
  return 0;
}

Error: WA

Fixed submission:

#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<ll, ll> ii;

#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define endl "\\n"
#define fx(n) fixed << setprecision(n)
#define mk make_pair

void File() {
#ifndef ONLINE_JUDGE
  freopen("output.txt", "w", stdout);
  freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
  /*freopen("output.txt", "w", stdout);
  freopen("commandos.in", "r", stdin);*/
#endif
}
void fast() {
  ios::sync_with_stdio(NULL);
  cout.tie(NULL);
  cin.tie(NULL);
  File();
}
const double pi = acos(-1.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 2e2 + 15;
int dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

int n, m;
vector<int> gr[nn];
int vis[nn];
void BFS(int S) {
  vector<int> dis(nn, oo);
  queue<pair<int, int>> qq;
  qq.push(make_pair(S, 0));
  dis[S] = 0;
  while (!qq.empty()) {
    pair<int, int> cur = qq.front();
    qq.pop();
    for (auto it : gr[cur.first]) {
      if (dis[it] > dis[cur.first] + 1) {
        dis[it] = dis[cur.first] + 1;
        qq.push(make_pair(it, dis[it]));
      }
    }
  }
  bool f = 0;
  for (int i = 2; i <= n && !f; i++) {
    if (dis[i] == oo)
      f = 1;
  }
  if (f)
    cout << "No\\n";
  else {
    cout << "Yes\\n";
    for (int i = 2; i <= n; i++)
      cout << dis[i] << endl;
  }
}
int main() {
  fast();
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    gr[u].push_back(v);
    gr[v].push_back(u);
  }
  BFS(1);
  return 0;
}