Language: C++

#include<bits/stdc++.h>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int INF=0x3f3f3f3f3f;
int main(){
	int h,w,cx,cy,dx,dy;
    cin>>h>>w>>cx>>cy>>dx>>dy;
    cx--;
    cy--;
    dx--;
    dy--;
    string s[h];
    for (int i=0;i<h;i++)cin >> s[i];
    deque<P> q;
    q.push_back(P(cx,cy));
    bool vis[h][w];
    int d[h][w];
    memset(vis,0,sizeof(vis));
    memset(d,INF,sizeof(d));
    d[cx][cy]=0;
    visited[cx][cy]=true;
	while(!q.empty()){
		P p=q.front();
        int X=p.first,Y=p.second;
        if(X==dx&&Y=dy){
        	cout<<d[X][Y];
        	return 0;
		}
		vis[X][Y]=true;
		q.pop_front();
		for(int i=-2;i<3;i++)
			for(int j=-2;j<3;j++){
				x=X+i;y=Y+j;
				if(x<h&&x>0&&y<w&&y>0&&s[x][y]=='.'){
					if(vis[x][y])continue;
					if(abs(i)+abs(j)<2){
						q.push_front(P(x,y));
						d[x][y]=d[X][Y];
						vis[x][y]=true;
					}
					else if(d[x][y]>d[X][Y]+1){
						d[x][y]=d[X][Y]+1;
						que.push_back(P(x,y));
					}
				}
			}
	}
	cout<<-1;
}

Compiler output:
a.cc:5:9: warning: overflow in conversion from 'long int' to 'int' changes value from '271644049215' to '1061109567' [-Woverflow]
    5 | int INF=0x3f3f3f3f3f;
      |         ^~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:15:11: error: 'P' was not declared in this scope
   15 |     deque<P> q;
      |           ^
a.cc:15:12: error: template argument 1 is invalid
   15 |     deque<P> q;
      |            ^
a.cc:15:12: error: template argument 2 is invalid
a.cc:16:7: error: request for member 'push_back' in 'q', which is of non-class type 'int'
   16 |     q.push_back(P(cx,cy));
      |       ^~~~~~~~~
a.cc:22:5: error: 'visited' was not declared in this scope
   22 |     visited[cx][cy]=true;
      |     ^~~~~~~
a.cc:23:18: error: request for member 'empty' in 'q', which is of non-class type 'int'
   23 |         while(!q.empty()){
      |                  ^~~~~
a.cc:24:18: error: expected ';' before 'p'
   24 |                 P p=q.front();
      |                  ^~
      |                  ;
a.cc:25:15: error: 'p' was not declared in this scope
   25 |         int X=p.first,Y=p.second;
      |               ^
a.cc:26:19: error: 'Y' was not declared in this scope
   26 |         if(X==dx&&Y=dy){
      |                   ^
a.cc:30:24: error: 'Y' was not declared in this scope
   30 |                 vis[X][Y]=true;
      |                        ^
a.cc:31:19: error: request for member 'pop_front' in 'q', which is of non-class type 'int'
   31 |                 q.pop_front();
      |                   ^~~~~~~~~
a.cc:34:33: error: 'x' was not declared in this scope
   34 |                                 x=X+i;y=Y+j;
      |                                 ^
a.cc:34:39: error: 'y' was not declared in this scope
   34 |                                 x=X+i;y=Y+j;
      |                                       ^
a.cc:38:51: error: request for member 'push_front' in 'q', which is of non-class type 'int'
   38 |                                                 q.push_front(P(x,y));
      |                                                   ^~~~~~~~~~
a.cc:44:49: error: 'que' was not declared in this scope
   44 |                                                 que.push_back(P(x,y));
      |                                                 ^~~