Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef double dbl;
typedef long long int lld;
#define MAX std::numeric_limits<lld>::max();
#define MIN std::numeric_limits<lld>::min();
#define FastIO                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
lld lvl[2001][2001];
void dfs(vector<lld> V[], lld s, lld i) {
  set<lld> visit;
  queue<lld> que;
  lld y, j;
  lvl[s][i] = 0;
  visit.insert(i);
  que.push(i);
  while (!que.empty()) {
    y = que.front();
    que.pop();
    for (j = 0; j < V[y].size(); j++) {
      if (!visit.count(V[y][j])) {
        visit.insert(V[y][j]);
        que.push(V[y][j]);
        lvl[s][V[y][j]] = lvl[s][y] + 1;
      }
    }
  }
}
int main() {
#ifndef ONLINE_JUDGE
  freopen("inputf.in", "r", stdin);
  freopen("outputf.in", "w", stdout);
#endif
  FastIO lld n, x;
  lld y, i;
  cin >> n;
  cin >> x;
  cin >> y;
  lld j;
  vector<lld> V[n + 1];
  for (i = 2; i <= n; i++) {
    lld j = i - 1;
    V[i].push_back(j);
    V[j].push_back(i);
  }
  V[x].push_back(y);
  V[y].push_back(x);
  for (i = 1; i <= n; i++) {
    dfs(V, i, i);
  }
  set<lld> dist[n];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      dist[lvl[i][j]].insert(((i + j) * (i + j + 1)) / 2 + j);
    }
  }
  for (i = 1; i < n; i++) {
    cout << dist[i].size() / 2;
    cout << "\n";
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef double dbl;
typedef long long int lld;
#define MAX std::numeric_limits<lld>::max();
#define MIN std::numeric_limits<lld>::min();
#define FastIO                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
lld lvl[2001][2001];
void dfs(vector<lld> V[], lld s, lld i) {
  set<lld> visit;
  queue<lld> que;
  lld y, j;
  lvl[s][i] = 0;
  visit.insert(i);
  que.push(i);
  while (!que.empty()) {
    y = que.front();
    que.pop();
    for (j = 0; j < V[y].size(); j++) {
      if (!visit.count(V[y][j])) {
        visit.insert(V[y][j]);
        que.push(V[y][j]);
        lvl[s][V[y][j]] = lvl[s][y] + 1;
      }
    }
  }
}
int main() {
  FastIO lld n, x;
  lld y, i;
  cin >> n;
  cin >> x;
  cin >> y;
  lld j;
  vector<lld> V[n + 1];
  for (i = 2; i <= n; i++) {
    lld j = i - 1;
    V[i].push_back(j);
    V[j].push_back(i);
  }
  V[x].push_back(y);
  V[y].push_back(x);
  for (i = 1; i <= n; i++) {
    dfs(V, i, i);
  }
  set<lld> dist[n];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      dist[lvl[i][j]].insert(((i + j) * (i + j + 1)) / 2 + j);
    }
  }
  for (i = 1; i < n; i++) {
    cout << dist[i].size() / 2;
    cout << "\n";
  }
  return 0;
}