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

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define ANTHRO(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define ANTHRO(x...)
#endif

#define ll long long
#define MOD 1000000007
#define INF (int)1e9
#define EPS 1e-9
/*
    This is 4.cpp
*/
#define cond (ll)2e3 + 17
/*vector<ll> ed[cond];
ll med(ll u,ll v, ll n){
    vector<bool> vis(n,0);
    vector<ll> dis(n,0);
    queue<ll> q;
    q.push(u);
    vis[u] = true;
    while (!q.empty())
    {
        int x = q.front();
        q.pop();

        for (int i=0; i<ed[x].size(); i++)
        {
            if (vis[ed[x][i]])
                continue;
            dis[ed[x][i]] = dis[x] + 1;
            q.push(ed[x][i]);
            vis[ed[x][i]] = 1;
        }
    }
    return dis[v];
}*/
/*void aE(ll u,ll v){
    ed[u].push_back(v);
    ed[v].push_back(u);//Undirected graph
}*/
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, x, y;
  cin >> n >> x >> y;
  vector<ll> dis(n + 1, 0);
  /*for(ll i=1;i<=n-1;i++){
      aE(i,i+1);
  }
  aE(x,y);*/
  for (ll i = 1; i < n; i++) {
    for (ll j = i + 1; j <= n; j++) {
      dis[min(abs(j - i), min((abs(x - i) + 1 + abs(y - j)),
                              (abs(y - i) + 1 + abs(x - j))))]++;
    }
  }
  for (ll i = 1; i < n; i++) {
    cout << dis[i] << "\\n";
  }
  return 0;
}


Error: -6
munmap_chunk(): invalid pointer


Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bitset>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define ANTHRO(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define ANTHRO(x...)
#endif

#define ll long long
#define MOD 1000000007
#define INF (int)1e9
#define EPS 1e-9
/*
    This is 4.cpp
*/
#define cond (ll)2e3 + 17
vector<ll> ed[cond];
ll med(ll u, ll v, ll n) {
  vector<bool> vis(n, 0);
  vector<ll> dis(n, 0);
  queue<ll> q;
  q.push(u);
  vis[u] = true;
  while (!q.empty()) {
    int x = q.front();
    q.pop();

    for (int i = 0; i < ed[x].size(); i++) {
      if (vis[ed[x][i]])
        continue;
      dis[ed[x][i]] = dis[x] + 1;
      q.push(ed[x][i]);
      vis[ed[x][i]] = 1;
    }
  }
  return dis[v];
}
void aE(ll u, ll v) {
  ed[u].push_back(v);
  ed[v].push_back(u); // Undirected graph
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n, x, y;
  cin >> n >> x >> y;
  vector<ll> dis(n + 1, 0);
  for (ll i = 1; i <= n - 1; i++) {
    aE(i, i + 1);
  }
  aE(x, y);
  for (ll i = 1; i < n; i++) {
    for (ll j = i + 1; j <= n; j++) {
      dis[med(i, j, n)]++;
    }
  }
  for (ll i = 1; i < n; i++) {
    cout << dis[i] << "\\n";
  }
  return 0;
}