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

// Template //
#include <bits/stdc++.h>
using namespace std;

// マクロ //
#define rep(i, N) for (int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
template <class T> lint gcd(T a, T b) {
  int t;
  while (b != 0) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}

template <class T> lint lcm(T a, T b) { return a * b / gcd(a, b); }

double distance(pii a, pii b) {
  double dist;
  dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
  return dist;
}

lint perm(int a) {
  lint perm = 1;
  for (int i = a; i >= 1; i--) {
    perm *= i;
  }
  return perm;
}

lint combination(int n, int m) {
  long double c = 1;
  for (int i = n, k = 1; i > m; i--, k++) {
    c *= i;
    c /= k;
  }
  return (lint)c;
}

template <class T, class Q> inline bool chmin(T &a, Q b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T, class Q> inline bool chmax(T &a, Q b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// 定数 //
#define pi acos(-1)
#define mod 1000000007
#define MOD 998244353
#define inf ((1LL << 62) - 1 + (1LL << 62))

// キーワード //
#define elif else if

// End of Template //

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, X, Y;
  cin >> N >> X >> Y;
  vvi graph(N);
  graph[X - 1].push_back(Y - 1);
  graph[Y - 1].push_back(X - 1);

  rep(i, N - 1) {
    graph[i].push_back(i + 1);
    graph[i + 1].push_back(i);
  }
  queue<int> seen;

  vi dist(N, -1);
  vi cnt(N, 0);

  rep(i, N) {
    seen.push(i);
    dist[i] = 0;
    while (seen.size()) {
      int v = seen.front();
      seen.pop();
      for (auto x : graph[v]) {
        if (dist[x] != -1)
          continue;
        seen.push(x);
        dist[x] = dist[v] + 1;
        cnt[dist[x] - 1]++;
      }
    }
    dist.assign(N, -1);
  }
  rep(i, N - 1) { cou(cnt[i] / 2); }
}

Error: WA

Fixed submission:

// Template //
#include <bits/stdc++.h>
using namespace std;

// マクロ //
#define rep(i, N) for (int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
template <class T> lint gcd(T a, T b) {
  int t;
  while (b != 0) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}

template <class T> lint lcm(T a, T b) { return a * b / gcd(a, b); }

double distance(pii a, pii b) {
  double dist;
  dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
  return dist;
}

lint perm(int a) {
  lint perm = 1;
  for (int i = a; i >= 1; i--) {
    perm *= i;
  }
  return perm;
}

lint combination(int n, int m) {
  long double c = 1;
  for (int i = n, k = 1; i > m; i--, k++) {
    c *= i;
    c /= k;
  }
  return (lint)c;
}

template <class T, class Q> inline bool chmin(T &a, Q b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T, class Q> inline bool chmax(T &a, Q b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// 定数 //
#define pi acos(-1)
#define mod 1000000007
#define MOD 998244353
#define inf ((1LL << 62) - 1 + (1LL << 62))

// キーワード //
#define elif else if

// End of Template //

vi distsonzai;
vb seen;

void dfs(vvi &graph, int n, int depth = 0) {
  seen[n] = true;
  distsonzai[depth]++;

  for (auto x : graph[n]) {
    if (seen[x])
      continue;
    dfs(graph, x, depth + 1);
  }
}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, X, Y;
  cin >> N >> X >> Y;
  distsonzai.assign(N, 0);
  seen.assign(N, false);

  vvi graph(N);
  rep(i, X + (Y - X - 1) / 2) {
    graph[i].push_back(i + 1);
    graph[i + 1].push_back(i);
  }
  do {
    graph[X - 1].push_back(Y - 1);
    graph[Y - 1].push_back(X - 1);
  } while (0);
  rep(i, N - Y) {
    graph[Y - 1 + i].push_back(Y + i);
    graph[Y + i].push_back(Y + i - 1);
  }
  rep(i, (Y - X - 1) / 2) {
    graph[Y - i].push_back(Y - i - 1);
    graph[Y - i - 1].push_back(Y - i);
  }
  rep(i, N) {
    dfs(graph, i);
    seen.assign(N, false);
  }
  for (int i = 1; i < N; i++) {
    cou(distsonzai[i]);
  }
}