Language: C++

#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<bits/stdc++.h>
#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define ss(a) scanf("%s",a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i,a,b) for(register int i=a;i<=b;++i)
#define repd(i,a,b) for(register int i=a;i>=b;--i)
#define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define ce(i,r) i==r?'\n':' '
#define pb push_back 
#define all(x) x.begin(),x.end()
#define fi first
#define se second
//#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;
const int N = 1e3 + 10;

int w,h,sw,sh,ew,eh;
char maze[N][N];
char vis[N][N];
int cnt[N][N];
int mv[2][4] = {{1,0,-1,0},{0,1,0,-1}};
queue<pair<int,int> > q1,q2,q3;

int main(){
	si(w),si(h);
	si(sw),si(sh);
	si(ew),si(eh);
	getchar();
	repi(i,1,w){
		repi(j,1,h){
			scanf("%c",&maze[i][j]);
			vis[i][j] = '*';
			cnt[i][j] = -1;
		}
		getchar();
	}
	q1.push({sw,sh});
	cnt[sw][sh] = 0;
	while(!q1.empty()){
		auto p = q1.front();
		q1.pop();
		int x = p.fi,y = p.se;
//		cout<<1<<':'<<x<<' '<<y<<' '<<maze[x][y]<<endl;
		if(vis[x][y] == '!')
			continue;
		q2.push({x,y});
		int flag = 0;
		while(!q2.empty()){
			auto p = q2.front();
			q2.pop();
			int x = p.fi,y = p.se;
//			cout<<2<<':'<<x<<' '<<y<<' '<<maze[x][y]<<endl;
			vis[x][y] = '!';
			int flag1 = 0;
			repi(k,0,3){
				int i = x + mv[0][k],j = y + mv[1][k];
				if(i > 0 && i <= w && j > 0 && j <= h  && vis[i][j] == '*'){
					if(maze[i][j] == '.'){
						vis[i][j] = '!';
						cnt[i][j] = cnt[x][y];
						if(i == ew && j == eh){
							flag = 1;
							break;
						}
						q2.push({i,j});
					}
					else{
						flag1 = 1;
					}
				}
				if(flag)
					break;
			}
			if(flag1)
				q3.push({x,y});
			if(flag)
				break;
		}
		if(flag)
			break;
		while(!q3.empty()){
			auto p = q3.front();
			q3.pop();
			int x = p.fi,y = p.se;
//			cout<<3<<':'<<x<<' '<<y<<' '<<maze[x][y]<<endl;
			repi(i,x - 2,x + 2){
					if(i > 0 && i <= w && j > 0 && j <= h  && vis[i][j] == '*' && maze[i][j] == '.'){
						cnt[i][j] = cnt[x][y] + 1;
						q1.push({i,j});
					} 
				}
			}
		}
		if(flag)
			break;
	}
	cout<<cnt[ew][eh]<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   34 |         repi(i,1,w){
      |              ^
a.cc:9:38: note: in definition of macro 'repi'
    9 | #define repi(i,a,b) for(register int i=a;i<=b;++i)
      |                                      ^
a.cc:35:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   35 |                 repi(j,1,h){
      |                      ^
a.cc:9:38: note: in definition of macro 'repi'
    9 | #define repi(i,a,b) for(register int i=a;i<=b;++i)
      |                                      ^
a.cc:60:30: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   60 |                         repi(k,0,3){
      |                              ^
a.cc:9:38: note: in definition of macro 'repi'
    9 | #define repi(i,a,b) for(register int i=a;i<=b;++i)
      |                                      ^
a.cc:91:30: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   91 |                         repi(i,x - 2,x + 2){
      |                              ^
a.cc:9:38: note: in definition of macro 'repi'
    9 | #define repi(i,a,b) for(register int i=a;i<=b;++i)
      |                                      ^
a.cc:92:63: error: 'j' was not declared in this scope
   92 |                                         if(i > 0 && i <= w && j > 0 && j <= h  && vis[i][j] == '*' && maze[i][j] == '.'){
      |                                                               ^
a.cc:94:56: error: no matching function for call to 'std::queue<std::pair<int, int> >::push(<brace-enclosed initializer list>)'
   94 |                                                 q1.push({i,j});
      |                                                 ~~~~~~~^~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:157,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_queue.h:283:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; value_type = std::pair<int, int>]'
  283 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:283:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::queue<std::pair<int, int> >::value_type&' {aka 'const std::pair<int, int>&'}
  283 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:288:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(value_type&&) [with _Tp = std::pair<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; value_type = std::pair<int, int>]'
  288 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:288:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::queue<std::pair<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  288 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
a.cc:99:20: error: 'flag' was not declared in this scope
   99 |                 if(flag)
      |                    ^~~~
a.cc:100:25: error: break statement not within loop or switch
  100 |                         break;
      |                         ^~~~~
a.cc: At global scope:
a.cc:102:9: error: 'cout' does not name a type
  102 |         cout<<cnt[ew][eh]<<endl;
      |         ^~~~
a.cc:103:9: error: expected unqualified-id before 'return'
  103 |         return 0;
      |         ^~~~~~
a.cc:104:1: error: expected declaration before '}' token
  104 | }
      | ^