Problem p02726 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define fl(i, a, n) for (int i = a; i < n; i++)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define test()                                                                 \\
  int tt;                                                                      \\
  cin >> tt;                                                                   \\
  while (tt--)
#define nl cout << "\\n"
#define pii pair<int, int>
#define dbg(args...)                                                           \\
  {                                                                            \\
    string _s = #args;                                                         \\
    replace(_s.begin(), _s.end(), ',', ' ');                                   \\
    stringstream _ss(_s);                                                      \\
    istream_iterator<string> _it(_ss);                                         \\
    err(_it, args);                                                            \\
  }
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << endl;
  err(++it, args...);
}
const int mod = 1e9 + 7;
int dist(int x, int y) { return abs(x - y); }
void solve() {
  int n, x, y;
  cin >> n >> x >> y;
  map<int, int> distance;
  fl(i, 1, n) {
    fl(j, i + 1, n + 1) {
      int temp = min(dist(i, j), min(dist(i, x) + 1 + dist(y, j),
                                     dist(i, y) + 1 + dist(x, j)));
      distance[temp]++;
    }
  }

  fl(i, 1, n) { cout << distance[i] << "\\n"; }
}
/*  Integer Overflow  */
int main() {
  fast;
  // test()
  solve();
}

Error: TLE

Fixed submission:

/*         Waha tufaan bhi haar jate hain...
        ...Jaha Kastiyan zid pe hoti hain
*/
#include <bits/stdc++.h>
using namespace std;

#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define fl(i, a, n) for (int i = a; i < n; i++)
#define rfl(i, a, n) for (int i = a; i >= n; i--)
#define ll long long
#define pb push_back
#define all(v) v.begin(), v.end()
#define in(arr, n) fl(i, 0, n) cin >> arr[i];
#define out(arr, n)                                                            \\
  fl(i, 0, n) cout << arr[i] << " ";                                           \\
  cout << endl;
#define test()                                                                 \\
  int tt;                                                                      \\
  cin >> tt;                                                                   \\
  while (tt--)

int minEdgeBFS(vector<int> edges[], int u, int v, int n) {
  // visited[n] for keeping track of visited
  // node in BFS
  vector<bool> visited(n, 0);

  // Initialize distances as 0
  vector<int> distance(n, 0);

  // queue to do BFS.
  queue<int> Q;
  distance[u] = 0;

  Q.push(u);
  visited[u] = true;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();

    for (int i = 0; i < edges[x].size(); i++) {
      if (visited[edges[x][i]])
        continue;

      // update distance for i
      distance[edges[x][i]] = distance[x] + 1;
      Q.push(edges[x][i]);
      visited[edges[x][i]] = 1;
    }
  }
  return distance[v];
}
void addEdge(vector<int> edges[], int u, int v) {
  edges[u].push_back(v);
  edges[v].push_back(u);
}
int main() {
  fast;
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> edges[n + 1];
  for (int i = 1; i <= n - 1; i++) {
    addEdge(edges, i, i + 1);
  }
  addEdge(edges, x, y);
  map<int, int> mp;
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      mp[minEdgeBFS(edges, i, j, n + 1)]++;
    }
  }
  for (int i = 1; i <= n - 1; i++)
    cout << mp[i] << "\\n";
}