Problem p02726 (C++)

Buggy submission (status: Runtime Error):
//  RAKSHIT KADAM
// ALWAYS USE &IT FOR ITERATING USING AUTO ...
// USE COUNT(STARTING ADDRESS, ENDING ADRESS ,VALUE) FOR FINDING THE COUNT IN
// THE RESPECTIVE DATA STRUCTURE NOTE THAT MEMSET CANNOT ASSIGN A VALUE OF 10^18
// IT WILL ASSIGN A LOWER VALUE THAN THAT!!! NOTE THAT MEMSET CANT FILL THE
// DOUBLE VALUES;
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,
// tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!

// NUMERIC DEFINITIONS :
#define INF 2000000000000000005
#define MOD 1000000007
#define newMOD 998244353
#define MAX 300006
#define pi 3.1415926535897932384626433832795
#define ld long double
#define ll long long
#define int long long

#define P(gg)                                                                  \
  for (auto rax : gg) {                                                        \
    cout << rax << " ";                                                        \
  }                                                                            \
  cout << endl;
#define Need_for_speed(activated)                                              \
  ios_base ::sync_with_stdio(0);                                               \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define satisfy                                                                \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--)
#define inp(n)                                                                 \
  int n;                                                                       \
  cin >> n
#define mp make_pair
#define pb push_back
#define endl "\n"
#define x first
#define y second
#define fore(i, a, b) for (ll i = a; i < b; i++)
#define forci(i, n) for (ll i = 0; i < n; i++)
#define vi vector<ll>
#define Endl endl
#define lb lower_bound
#define ub upper_bound
#define pii pair<ll, ll>

#define input                                                                  \
  freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define time                                                                   \
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int power(int x, unsigned int y, unsigned int m) {
  if (y == 0)
    return 1;
  int p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
ll modInverse(int a, int m) {
  int g = gcd(a, m);
  { return power(a, m - 2, m); }
}

ll n;
// DIJSTRAS ALGORITHM ,DECLARE PARENT,VIS, DISTANCE ARRAYS...

// pair of distance, the vertex
ll dis[10004];
vector<pii> v[2000];
ll ans[2003];
void dijikstra(ll source) {
  ll parent[n + 3];
  memset(parent, 0, sizeof parent);
  ll vis[n + 3];
  for (ll i = 0; i <= n; i++)
    vis[i] = 0;
  multiset<pair<ll, ll>> m;

  m.insert(mp(0, source));
  parent[source] = source;

  for (ll i = 0; i < n + 2; i++)
    dis[i] = 1e12;
  dis[source] = 0;
  while (m.size()) {
    pair<ll, ll> p = *m.begin();

    ll x = p.first, y = p.second;
    m.erase(m.begin());
    if (vis[y])
      continue;
    vis[y] = 1;

    for (ll i = 0; i < v[y].size(); i++) {

      ll ax = v[y][i].first;
      ll ay = v[y][i].second;
      if (dis[y] + ax < dis[ay]) {
        dis[ay] = ax + dis[y];
        m.insert(mp(dis[ay], ay));
        parent[ay] = y;
      }
    }
  }
  for (ll i = 1; i <= n; i++)
    ans[dis[i]]++;
}
void solve() {
  cin >> n;
  ll x, y;
  cin >> x >> y;
  for (ll i = 1; i <= n - 1; i++) {
    v[i].pb(mp(1, i + 1));
    v[i + 1].pb(mp(1, i));
  }
  v[x].pb(mp(1, y));
  v[y].pb(mp(1, x));
  for (ll i = 1; i <= n; i++) {
    dijikstra(i);
    memset(dis, 0, sizeof dis);
  }
  for (ll i = 1; i <= n - 1; i++)
    cout << ans[i] / 2 << endl;
}

signed main() {

  Need_for_speed(activated);
  // satisfy
  //     {
  //    solve();
  //    }

  solve();
  return 0;
}


Fixed submission:
//  RAKSHIT KADAM
// ALWAYS USE &IT FOR ITERATING USING AUTO ...
// USE COUNT(STARTING ADDRESS, ENDING ADRESS ,VALUE) FOR FINDING THE COUNT IN
// THE RESPECTIVE DATA STRUCTURE NOTE THAT MEMSET CANNOT ASSIGN A VALUE OF 10^18
// IT WILL ASSIGN A LOWER VALUE THAN THAT!!! NOTE THAT MEMSET CANT FILL THE
// DOUBLE VALUES;
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,
// tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!

// NUMERIC DEFINITIONS :
#define INF 2000000000000000005
#define MOD 1000000007
#define newMOD 998244353
#define MAX 300006
#define pi 3.1415926535897932384626433832795
#define ld long double
#define ll long long
#define int long long

#define P(gg)                                                                  \
  for (auto rax : gg) {                                                        \
    cout << rax << " ";                                                        \
  }                                                                            \
  cout << endl;
#define Need_for_speed(activated)                                              \
  ios_base ::sync_with_stdio(0);                                               \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)
#define satisfy                                                                \
  ll t;                                                                        \
  cin >> t;                                                                    \
  while (t--)
#define inp(n)                                                                 \
  int n;                                                                       \
  cin >> n
#define mp make_pair
#define pb push_back
#define endl "\n"
#define x first
#define y second
#define fore(i, a, b) for (ll i = a; i < b; i++)
#define forci(i, n) for (ll i = 0; i < n; i++)
#define vi vector<ll>
#define Endl endl
#define lb lower_bound
#define ub upper_bound
#define pii pair<ll, ll>

#define input                                                                  \
  freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define time                                                                   \
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int power(int x, unsigned int y, unsigned int m) {
  if (y == 0)
    return 1;
  int p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
ll modInverse(int a, int m) {
  int g = gcd(a, m);
  { return power(a, m - 2, m); }
}

ll n;
// DIJSTRAS ALGORITHM ,DECLARE PARENT,VIS, DISTANCE ARRAYS...

// pair of distance, the vertex
ll dis[10004];
vector<pii> v[2003];
ll ans[2003];
void dijikstra(ll source) {
  ll parent[n + 3];
  memset(parent, 0, sizeof parent);
  ll vis[n + 3];
  for (ll i = 0; i <= n; i++)
    vis[i] = 0;
  multiset<pair<ll, ll>> m;

  m.insert(mp(0, source));
  parent[source] = source;

  for (ll i = 0; i < n + 2; i++)
    dis[i] = 1e12;
  dis[source] = 0;
  while (m.size()) {
    pair<ll, ll> p = *m.begin();

    ll x = p.first, y = p.second;
    m.erase(m.begin());
    if (vis[y])
      continue;
    vis[y] = 1;

    for (ll i = 0; i < v[y].size(); i++) {

      ll ax = v[y][i].first;
      ll ay = v[y][i].second;
      if (dis[y] + ax < dis[ay]) {
        dis[ay] = ax + dis[y];
        m.insert(mp(dis[ay], ay));
        parent[ay] = y;
      }
    }
  }
  for (ll i = 1; i <= n; i++)
    ans[dis[i]]++;
}
void solve() {
  cin >> n;
  ll x, y;
  cin >> x >> y;
  for (ll i = 1; i <= n - 1; i++) {
    v[i].pb(mp(1, i + 1));
    v[i + 1].pb(mp(1, i));
  }
  v[x].pb(mp(1, y));
  v[y].pb(mp(1, x));
  for (ll i = 1; i <= n; i++) {
    dijikstra(i);
    memset(dis, 0, sizeof dis);
  }
  for (ll i = 1; i <= n - 1; i++)
    cout << ans[i] / 2 << endl;
}

signed main() {

  Need_for_speed(activated);
  // satisfy
  //     {
  //    solve();
  //    }

  solve();
  return 0;
}