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

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int INF = 1e3 + 125;
const int dfx[] = {0, 0, 1, -1}, dfy[] = {1, -1, 0, 0};
const int bfx[] = {-2, -2, -2, -2, -2, -1, -1, -1, -1, 0,
                   0,  1,  1,  1,  1,  2,  2,  2,  2,  2};
const int bfy[] = {-2, -1, 0,  1, 2, -2, -1, 1, 2, -2,
                   2,  -2, -1, 1, 2, -2, -1, 0, 1, 2};
int h, w, cx, cy, dx, dy, qx[INF * INF * 30 + 25], qy[INF * INF * 30 + 25], l,
    r, dis_[INF][INF];
bool vis[INF][INF];
char Map[INF][INF];
void DFS(int x, int y) {
  for (int i = 0; i < 4; i++) {
    int gx = x + dfx[i], gy = y + dfy[i];
    if (gx < 1 || gy < 1 || gx > h || gy > w || Map[gx][gy] != '.' ||
        dis_[gx][gy] <= dis_[x][y])
      continue;
    vis[gx][gy] = true;
    dis_[gx][gy] = dis_[x][y];
    qx[++r] = gx;
    qy[r] = gy;
    DFS(gx, gy);
  }
  return;
}
void BFS() {
  memset(dis_, 63, sizeof dis_);
  vis[cx][cy] = true;
  dis_[cx][cy] = 0;
  DFS(cx, cy);
  // bool flag=false;
  while (l <= r) {
    int x = qx[l], y = qy[l];
    l++;
    // if (vis[dx][dy]) flag=true;
    // if (flag) break;
    for (int i = 0; i < 20; i++) {
      int gx = x + bfx[i], gy = y + bfy[i];
      if (gx < 1 || gy < 1 || gx > h || gy > w || Map[gx][gy] != '.' ||
          dis_[gx][gy] < dis_[x][y] + 1 || vis[gx][gy])
        continue;
      dis_[gx][gy] = dis_[x][y] + 1;
      vis[gx][gy] = true;
      DFS(gx, gy);
      // if (vis[dx][dy]) flag=true;
      // if (flag) break;
      qx[++r] = gx;
      qy[r] = gy;
    }
    // if (flag) break;
  }
  return;
}
signed main() {

  scanf("%d %d", &h, &w);
  scanf("%d %d %d %d ", &cx, &cy, &dx, &dy);
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++)
      cin >> Map[i][j];
  }
  // cout<<"ok\\n";
  l = 1;
  qx[++r] = cx;
  qy[r] = cy;
  BFS();
  if (vis[dx][dy])
    cout << dis_[dx][dy] << "\\n";
  else
    cout << "-1\\n";
  return 0;
}


Error: -11

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
#define int long long
using namespace std;
const int INF = 1e3 + 125;
const int dfx[] = {0, 0, 1, -1}, dfy[] = {1, -1, 0, 0};
const int bfx[] = {-2, -2, -2, -2, -2, -1, -1, -1, -1, 0,
                   0,  1,  1,  1,  1,  2,  2,  2,  2,  2};
const int bfy[] = {-2, -1, 0,  1, 2, -2, -1, 1, 2, -2,
                   2,  -2, -1, 1, 2, -2, -1, 0, 1, 2};
int h, w, cx, cy, dx, dy, qx[INF * INF * 30 + 25], qy[INF * INF * 30 + 25], l,
    r, dis_[INF][INF];
bool vis[INF][INF];
char Map[INF][INF];
void DFS(int x, int y) {
  for (int i = 0; i < 4; i++) {
    int gx = x + dfx[i], gy = y + dfy[i];
    if (gx < 1 || gy < 1 || gx > h || gy > w || Map[gx][gy] != '.' ||
        dis_[gx][gy] <= dis_[x][y] || vis[gx][gy])
      continue;
    vis[gx][gy] = true;
    dis_[gx][gy] = dis_[x][y];
    qx[++r] = gx;
    qy[r] = gy;
    DFS(gx, gy);
  }
  return;
}
void BFS() {
  memset(dis_, 63, sizeof dis_);
  vis[cx][cy] = true;
  dis_[cx][cy] = 0;
  // bool flag=false;
  while (l <= r) {
    int x = qx[l], y = qy[l];
    l++;
    DFS(x, y);
    // if (vis[dx][dy]) flag=true;
    // if (flag) break;
    for (int i = 0; i < 20; i++) {
      int gx = x + bfx[i], gy = y + bfy[i];
      if (gx < 1 || gy < 1 || gx > h || gy > w || Map[gx][gy] != '.' ||
          dis_[gx][gy] < dis_[x][y] + 1)
        continue;
      dis_[gx][gy] = dis_[x][y] + 1;
      vis[gx][gy] = true;
      // if (vis[dx][dy]) flag=true;
      // if (flag) break;
      qx[++r] = gx;
      qy[r] = gy;
    }
    // if (flag) break;
    // for (int i=1; i<=h; i++) {
    //         for (int j=1; j<=w; j++)
    //                 cout<<dis_[i][j]<<" ";
    //         cout<<endl;
    // }
  }
  return;
}
signed main() {
  scanf("%lld %lld", &h, &w);
  scanf("%lld %lld %lld %lld ", &cx, &cy, &dx, &dy);
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++)
      cin >> Map[i][j];
  }
  // cout<<"ok\\n";
  l = 1;
  qx[++r] = cx;
  qy[r] = cy;
  BFS();
  if (vis[dx][dy])
    cout << dis_[dx][dy] << "\\n";
  else
    cout << "-1\\n";
  return 0;
}