Problem p02726 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
using namespace std;
int dt[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {0, 0}};
// typedef pair<int, int> P;
// priority_queue<int, vector<int>, greater<int> > q;
const int manx = 2e3 + 10; // 顶点个数的最大范围
const int mamx = 2e3 + 10; // 边数的最大范围（最多有几条路，可以看）
int cnt[manx];
struct node {
  int v, next, w;
} a[mamx];
int d[manx][manx], head[manx];
bool vis[manx];
int n, m, s, e, k = 0;
void add(int u, int v, int w) {
  a[++k].next = head[u];
  head[u] = k;
  a[k].v = v;
  a[k].w = w;
}
void dij() {
  for (int i = 1; i <= n; i++)
    d[s][i] = 1e9;
  memset(vis, 0, sizeof(vis));
  priority_queue<pair<int, int>> q;
  d[s][s] = 0;
  q.push(make_pair(0, s));
  while (q.size()) {
    int u = q.top().second;
    q.pop();
    if (vis[u])
      continue;
    vis[u] = 1;
    for (int i = head[u]; i; i = a[i].next) {
      int v = a[i].v, w = a[i].w;
      if (d[s][v] > d[s][u] + w)
        d[s][v] = d[s][u] + w, q.push(make_pair(-d[s][v], v));
    }
  }
}
int main() {
  int x, y;
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++) {
    add(i, i + 1, 1);
    add(i + 1, i, 1);
  }
  add(x, y, 1);
  add(y, x, 1);
  for (int i = 1; i <= n; i++)
    s = i, dij();
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      cnt[d[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++)
    cout << cnt[i] << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
using namespace std;
int dt[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {0, 0}};
// typedef pair<int, int> P;
// priority_queue<int, vector<int>, greater<int> > q;
const int manx = 2e3 + 10; // 顶点个数的最大范围
const int mamx = 2e4 + 10; // 边数的最大范围（最多有几条路，可以看）
int cnt[manx];
struct node {
  int v, next, w;
} a[mamx];
int d[manx][manx], head[manx];
bool vis[manx];
int n, m, s, e, k = 0;
void add(int u, int v, int w) {
  a[++k].next = head[u];
  head[u] = k;
  a[k].v = v;
  a[k].w = w;
}
void dij() {
  for (int i = 1; i <= n; i++)
    d[s][i] = 1e9;
  memset(vis, 0, sizeof(vis));
  priority_queue<pair<int, int>> q;
  d[s][s] = 0;
  q.push(make_pair(0, s));
  while (q.size()) {
    int u = q.top().second;
    q.pop();
    if (vis[u])
      continue;
    vis[u] = 1;
    for (int i = head[u]; i; i = a[i].next) {
      int v = a[i].v, w = a[i].w;
      if (d[s][v] > d[s][u] + w)
        d[s][v] = d[s][u] + w, q.push(make_pair(-d[s][v], v));
    }
  }
}
int main() {
  int x, y;
  cin >> n >> x >> y;
  for (int i = 1; i <= n; i++) {
    add(i, i + 1, 1);
    add(i + 1, i, 1);
  }
  add(x, y, 1);
  add(y, x, 1);
  for (int i = 1; i <= n; i++)
    s = i, dij();
  for (int i = 1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      cnt[d[i][j]]++;
    }
  }
  for (int i = 1; i < n; i++)
    cout << cnt[i] << endl;
}