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

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout << s, 0
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(), v.end()
#define watch(x) cout << (#x) << " = " << x << endl
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
#if __cplusplus >= 201402L
template <typename T> vector<T> create(size_t n) { return vector<T>(n); }
template <typename T, typename... Args> auto create(size_t n, Args... args) {
  return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifdef EZZAT
  freopen("input.in", "r", stdin);
  // freopen("output.out", "w", stdout);
#else
#endif
}

const int N = 2e3 + 9;
vector<int> adj[N];
vector<int> dis[N];
int n;
void bfs(int node) {
  vector<int> &len = dis[node];
  len = vector<int>(n + 1, oo);
  len[node] = 0;
  queue<int> q;
  q.push(node);
  while (sz(q)) {
    node = q.front();
    q.pop();
    for (int ch : adj[node]) {
      if (len[ch] > len[node] + 1) {
        len[ch] = len[node] + 1;
        q.push(ch);
      }
    }
  }
}
int main() {
  run();
  int x, y;
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++)
    adj[i].push_back(i + 1), adj[i + 1].push_back(i);
  adj[x].push_back(y);
  adj[y].push_back(x);
  map<int, int> mp;
  for (int i = 1; i <= n; i++)
    bfs(i);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      mp[dis[i][j]]++;
  for (int k = 1; k < n; k++)
    cout << mp[k] << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout << s, 0
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(), v.end()
#define watch(x) cout << (#x) << " = " << x << endl
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
#if __cplusplus >= 201402L
template <typename T> vector<T> create(size_t n) { return vector<T>(n); }
template <typename T, typename... Args> auto create(size_t n, Args... args) {
  return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifdef EZZAT
  freopen("input.in", "r", stdin);
  // freopen("output.out", "w", stdout);
#else
#endif
}

const int N = 1e3 + 9;
vector<int> adj[N];
vector<int> dis[N];
int n;
void bfs(int node) {
  vector<int> &len = dis[node];
  len = vector<int>(n + 1, oo);
  len[node] = 0;
  queue<int> q;
  q.push(node);
  while (sz(q)) {
    node = q.front();
    q.pop();
    for (int ch : adj[node]) {
      if (len[ch] > len[node] + 1) {
        len[ch] = len[node] + 1;
        q.push(ch);
      }
    }
  }
}
int main() {
  run();
  int x, y;
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++)
    adj[i].push_back(i + 1), adj[i + 1].push_back(i);
  adj[x].push_back(y);
  adj[y].push_back(x);
  map<int, int> mp;
  for (int i = 1; i <= n; i++)
    bfs(i);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      mp[dis[i][j]]++;
  for (int k = 1; k < n; k++)
    cout << mp[k] << endl;
}