Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a) * (b)).imag()
#define dot(a, b) (conj(a) * (b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO                                                                 \
  freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set                                                            \
  tree<int, null_type, less_equal<int>, rb_tree_tag,                           \
       tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = {{1, 2},  {-1, 2},  {2, 1},  {2, -1},
                         {-2, 1}, {-2, -1}, {1, -2}, {-1, -2}};

int N = 1e3 + 7;

vector<int> conn[1007];
bool vis[1007];
int dist[1007];

void bfs(int src) {
  queue<int> q;
  q.push(src);
  dist[src] = 0;
  vis[src] = 1;
  while (q.size()) {
    int node = q.front();
    q.pop();
    for (auto i : conn[node]) {
      if (!vis[i]) {
        vis[i] = 1;
        q.push(i);
        dist[i] = dist[node] + 1;
      }
    }
  }
}

int main() {
  fastIO;
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++) {
    conn[i].push_back(i + 1);
    conn[i + 1].push_back(i);
  }
  conn[x].push_back(y);
  conn[y].push_back(x);

  map<int, int> count;
  for (int i = 1; i <= n; i++) {
    memset(vis, 0, sizeof vis);
    bfs(i);
    for (int j = i + 1; j <= n; j++) {
      count[dist[j]]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << count[i] << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a) * (b)).imag()
#define dot(a, b) (conj(a) * (b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO                                                                 \
  freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set                                                            \
  tree<int, null_type, less_equal<int>, rb_tree_tag,                           \
       tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = {{1, 2},  {-1, 2},  {2, 1},  {2, -1},
                         {-2, 1}, {-2, -1}, {1, -2}, {-1, -2}};

int N = 1e3 + 7;

vector<int> conn[2007];
bool vis[2007];
int dist[2007];

void bfs(int src) {
  queue<int> q;
  q.push(src);
  dist[src] = 0;
  vis[src] = 1;
  while (q.size()) {
    int node = q.front();
    q.pop();
    for (auto i : conn[node]) {
      if (!vis[i]) {
        vis[i] = 1;
        q.push(i);
        dist[i] = dist[node] + 1;
      }
    }
  }
}

int main() {
  fastIO;
  int n, x, y;
  cin >> n >> x >> y;
  for (int i = 1; i < n; i++) {
    conn[i].push_back(i + 1);
    conn[i + 1].push_back(i);
  }
  conn[x].push_back(y);
  conn[y].push_back(x);

  map<int, int> count;
  for (int i = 1; i <= n; i++) {
    memset(vis, 0, sizeof vis);
    bfs(i);
    for (int j = i + 1; j <= n; j++) {
      count[dist[j]]++;
    }
  }

  for (int i = 1; i < n; i++) {
    cout << count[i] << endl;
  }
}