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

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 1001001001001001001
#define MAX 2001001

#define rep(i, n, m) for (int i = n; i < m; i++)

using namespace std;

int main() {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  vector<vector<char>> s(h, vector<char>(w));
  rep(i, 0, h) rep(j, 0, w) cin >> s[i][j];

  ch--;
  cw--;
  dh--;
  dw--;
  vector<pair<int, int>> m{{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
  vector<vector<bool>> been(h, vector<bool>(w, 0));
  vector<vector<int>> warp(h, vector<int>(w, MAX));
  queue<pair<int, int>> que, quew;
  quew.push({ch, cw});
  warp[ch][cw] = 0;
  while (!quew.empty()) {
    int a, b;
    a = quew.front().first;
    b = quew.front().second;
    if (been[a][b]) {
      quew.pop();
      continue;
    }
    que.push({a, b});
    been[a][b] = true;
    while (!que.empty()) {
      int x, y;
      x = que.front().first;
      y = que.front().second;
      rep(i, 0, 5) rep(j, 0, 5) {
        int nx, ny;
        nx = x + i - 2;
        ny = y + j - 2;
        if (i == 2 && j == 2)
          continue;
        if (nx >= 0 && nx < h && ny >= 0 && ny < w) {
          if (s[nx][ny] == '#')
            continue;
          warp[nx][ny] = min(warp[nx][ny], warp[x][y] + 1);
          quew.push({nx, ny});
        }
      }
      rep(i, 0, 4) {
        int nx, ny;
        nx = x + m[i].first;
        ny = y + m[i].second;
        if (nx >= 0 && nx < h && ny >= 0 && ny < w) {
          if (s[nx][ny] == '#')
            continue;
          if (been[nx][ny])
            continue;
          been[nx][ny] = true;
          warp[nx][ny] = min(warp[nx][ny], warp[x][y]);
          que.push({nx, ny});
        }
      }
      que.pop();
    }
    quew.pop();
  }
  if (warp[dh][dw] == MAX)
    cout << -1 << endl;
  else
    cout << warp[dh][dw] << endl;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 1001001001001001001
#define MAX 2001001

#define rep(i, n, m) for (int i = n; i < m; i++)

using namespace std;

int main() {
  int h, w, ch, cw, dh, dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  vector<vector<char>> s(h, vector<char>(w));
  rep(i, 0, h) rep(j, 0, w) cin >> s[i][j];

  h--;
  w--;
  ch--;
  cw--;
  dh--;
  dw--;
  vector<pair<int, int>> m{{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
  vector<vector<bool>> been(h, vector<bool>(w, 0));
  vector<vector<int>> warp(h, vector<int>(w, MAX));
  stack<pair<int, int>> st, stw;
  stw.push({ch, cw});
  warp[ch][cw] = 0;
  while (!stw.empty()) {
    int a, b;
    a = stw.top().first;
    b = stw.top().second;
    if (been[a][b]) {
      stw.pop();
      continue;
    }
    st.push({a, b});
    been[a][b] = true;
    while (!st.empty()) {
      int x, y;
      x = st.top().first;
      y = st.top().second;
      rep(i, 0, 5) rep(j, 0, 5) {
        int nx, ny;
        nx = x + i - 2;
        ny = y + j - 2;
        if (i == 2 && j == 2)
          continue;
        if (nx >= 0 && nx < h && ny >= 0 && ny < w) {
          if (been[nx][ny])
            continue;
          if (s[nx][ny] == '#')
            continue;
          warp[nx][ny] = min(warp[nx][ny], warp[x][y] + 1);
          stw.push({nx, ny});
        }
      }
      rep(i, 0, 4) {
        int nx, ny;
        nx = x - m[i].first;
        ny = y - m[i].second;
        if (nx >= 0 && nx < h && ny >= 0 && ny < w) {
          if (been[nx][ny])
            continue;
          if (s[nx][ny] == '#')
            continue;
          been[nx][ny] = true;
          warp[nx][ny] = warp[x][y];
          st.push({nx, ny});
        }
      }
      st.pop();
    }
    stw.pop();
  }
  if (warp[dh][dw] == MAX)
    cout << -1 << endl;
  else
    cout << warp[dh][dw] << endl;
}