Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,f,n) for(int i=f; i<(n); i++)

int vec_h[4]={1,0,-1,0};
int vec_w[4]={0,1,0,-1};
char m[100000][100000];
int seen[100000][100000];
vector<pair<int,int>> se[100];
int mh, mw, gh ,gw;
int w_c = 0;

void tans(int h, int w, int t){
  seen[h][w] = t+1;
  se[t].push_back({h,w});
  REP(i,0,4){
    int nh = h + vec_h[i];
    int nw = w + vec_w[i];
    if(0 <= nh && nh < mh
      && 0 <= nw && nw < mw){
        if(seen[nh][nw] >= t+1)continue;
        if(m[nh][nw] == '#'){
          continue;
        }
        //cout << "*" << nh << ", " << nw << endl;  //--debug
        tans(nh, nw, t);
      }
  }
}

void serchiz(int nh, int nw){
  int t = w_c;
  tans(nh, nw, t);
  if(seen[gh][gw]!=0){
    //cout << "@" << nh << ", " << nw << endl;  //--debug
  }else{
    //cout << "#" << nh << ", " << nw << endl;  //--debug
    w_c++;
    for(auto c:se[t]){
      int h2 = c.first;
      int w2 = c.second;
      REP(i,-2,3){
        REP(j,-2,3){
          if(i==0 && j==0)continue;
          int nh2 = h2+i;
          int nw2 = w2+j;
          if(0 <= nh2 && nh2 < mh
          && 0 <= nw2 && nw2 < mw){
            if(m[nh2][nw2] == '#'){
              continue;
            }
            if(seen[nh2][nw2]==0){
              serchiz(nh2, nw2);
            }
          }
        }
      }
    }
  }
  if(seen[gh][gw]==0)w_c=-1;
}

int main()
{
  int h, w, sh, sw;
  cin >> h >> w;
  mh = h; mw = w;
  cin >> sh >> sw;
  cin >> gh >> gw;
  sh--;
  sw--;
  gh--;
  gw--;
  REP(i,0,h){
    REP(j,0,w){
      cin >> m[i][j];
      seen[i][j]=0;
    }
  }

  serchiz(sh, sw);

  cout << w_c << endl;

  //--debug : end_stoper
  //string end_stoper; cin >> end_stoper;

  return 0;
}

Compiler output:
/tmp/ccznDDVy.o: in function `tans(int, int, int)':
a.cc:(.text+0x38): relocation truncated to fit: R_X86_64_PC32 against symbol `seen' defined in .bss section in /tmp/ccznDDVy.o
a.cc:(.text+0x55): relocation truncated to fit: R_X86_64_PC32 against symbol `se' defined in .bss section in /tmp/ccznDDVy.o
a.cc:(.text+0xd9): relocation truncated to fit: R_X86_64_PC32 against symbol `mh' defined in .bss section in /tmp/ccznDDVy.o
a.cc:(.text+0xea): relocation truncated to fit: R_X86_64_PC32 against symbol `mw' defined in .bss section in /tmp/ccznDDVy.o
a.cc:(.text+0x113): relocation truncated to fit: R_X86_64_PC32 against symbol `seen' defined in .bss section in /tmp/ccznDDVy.o
/tmp/ccznDDVy.o: in function `serchiz(int, int)':
a.cc:(.text+0x183): relocation truncated to fit: R_X86_64_PC32 against symbol `w_c' defined in .bss section in /tmp/ccznDDVy.o
a.cc:(.text+0x19e): relocation truncated to fit: R_X86_64_PC32 against symbol `gh' defined in .bss section in /tmp/ccznDDVy.o
a.cc:(.text+0x1a4): relocation truncated to fit: R_X86_64_PC32 against symbol `gw' defined in .bss section in /tmp/ccznDDVy.o
a.cc:(.text+0x1c2): relocation truncated to fit: R_X86_64_PC32 against symbol `seen' defined in .bss section in /tmp/ccznDDVy.o
a.cc:(.text+0x1d3): relocation truncated to fit: R_X86_64_PC32 against symbol `w_c' defined in .bss section in /tmp/ccznDDVy.o
a.cc:(.text+0x1dc): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status