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

// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

// PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define repp(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, b, a) for (int i = b; i >= a; i--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mem(a, b) memset(a, b, sizeof(a));
#define mem0(a) memset(a, 0, sizeof(a));
#define quickio                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define in_edges(m)                                                            \\
  repp(i, 1, m) {                                                              \\
    ll a, b;                                                                   \\
    cin >> a >> b;                                                             \\
    v[a].pb(b), v[b].pb(a);                                                    \\
  }
#define debug(this) cerr << "> " << #this << " : " << this << "\\n"
#define endl "\\n"
ll power(ll x, ll y);

const ll MOD = 1000000007;

vector<ll> v[2003];
bool vis[2003];
ll level[2003];
ll dis[2003];
ll n, x, y;

ll mat[2001][2001];

void bfs(ll s) {
  mem0(level);
  queue<ll> q;
  q.push(s);
  vis[s] = 1;
  while (!q.empty()) {
    ll p = q.front();
    q.pop();
    for (auto i : v[p]) {
      if (vis[i])
        continue;
      level[i] = level[p] + 1;
      q.push(i);
      vis[i] = 1;
    }
  }

  repp(i, 1, n) mat[i][s] = mat[s][i] = level[i];
  // repp(i, 1, n) cout << level[i] << " "; cout << endl;
  // repp(i, 0, 1000) dis[level[i]]++;
}

int main() // PointBlank's code ¯\\_(ツ)_/¯
{
  cin >> n >> x >> y;
  repp(i, 1, n - 1) {
    v[i].pb(i + 1);
    v[i + 1].pb(i);
  }
  v[x].pb(y);
  v[y].pb(x);

  repp(i, 1, n) {
    mem0(vis);
    bfs(i);
  }

  repp(i, 1, n) repp(j, 1, n) if (i <= j) dis[mat[i][j]]++;

  rep(i, 1, n) cout << dis[i] << endl;
}

ll power(ll x, ll y) {
  ll res = 1;
  x %= MOD;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % MOD;
    y = y >> 1, x = (x * x) % MOD;
  }
  return res;
}

Error: 0

Fixed submission:

// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

// PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define repp(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, b, a) for (int i = b; i >= a; i--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define mem(a, b) memset(a, b, sizeof(a));
#define mem0(a) memset(a, 0, sizeof(a));
#define quickio                                                                \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define in_edges(m)                                                            \\
  repp(i, 1, m) {                                                              \\
    ll a, b;                                                                   \\
    cin >> a >> b;                                                             \\
    v[a].pb(b), v[b].pb(a);                                                    \\
  }
#define debug(this) cerr << "> " << #this << " : " << this << "\\n"
#define endl "\\n"
ll power(ll x, ll y);

const ll MOD = 1000000007;

vector<ll> v[1003];
bool vis[1003];
ll level[1003];
ll dis[1003];
ll n, x, y;

ll mat[1001][1001];

void bfs(ll s) {
  mem0(level);
  queue<ll> q;
  q.push(s);
  vis[s] = 1;
  while (!q.empty()) {
    ll p = q.front();
    q.pop();
    for (auto i : v[p]) {
      if (vis[i])
        continue;
      level[i] = level[p] + 1;
      q.push(i);
      vis[i] = 1;
    }
  }

  repp(i, 1, n) mat[i][s] = mat[s][i] = level[i];
  // repp(i, 1, n) cout << level[i] << " "; cout << endl;
  // repp(i, 0, 1000) dis[level[i]]++;
}

int main() // PointBlank's code ¯\\_(ツ)_/¯
{
  cin >> n >> x >> y;
  repp(i, 1, n - 1) {
    v[i].pb(i + 1);
    v[i + 1].pb(i);
  }
  v[x].pb(y);
  v[y].pb(x);

  repp(i, 1, n) {
    mem0(vis);
    bfs(i);
  }

  repp(i, 1, n) repp(j, 1, n) if (i <= j) dis[mat[i][j]]++;

  rep(i, 1, n) cout << dis[i] << endl;
}

ll power(ll x, ll y) {
  ll res = 1;
  x %= MOD;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % MOD;
    y = y >> 1, x = (x * x) % MOD;
  }
  return res;
}