Language: C++

#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
#define maxval 10003000
vector<pll> adj[10001][10001];
ll visit[10001][10001];
ll ans[10001][10001];
ll edge[10001][10001][10001][10001];
ll ans1=LONG_MAX;
void bfs(ll i,ll j,ll d1,ll d2){
    for(ll i1 = 0; i1 < 10001; i1++) {
     for(ll j1=0;j1<10001;j1++){visit[i1][j1]=0;
     }}
     queue<pll> q;
     q.push({i,j});
    while (!q.empty()) { 

        pll s = q.front(); 
        q.pop(); 
     
        for (ll x=0;x<adj[s.first][s.second].size(); ++x) { 
           pll z;
          z={adj[s.first][s.second][x].first,adj[s.first][s.second][x].second};
         
       
            if(edge[i][j][z.first][z.second]==2) ans[z.first][z.second]=ans[i][j]+1;
            if (visit[z.first][z.second]==0) { 
               visit[z.first][z.second]=1;
                q.push(z); 
            } 
        } 
    } 
}


int main(){
   IOS;
ll t;t=1;//cin>>t;

while(t--){
    ll n,m;cin>>n>>m;
    ll in1,in2,ou1,ou2;
    cin>>in1>>in2>>ou1>>ou2;
    ll a[n+4][m+4];
    for(ll i=2;i<n+2;i++){
        for(ll j=2;j<m+2;j++) cin>>a[i][j];
    }
   for(ll i=2;i<n+2;i++){
       for(ll j=2;j<m+2;j++){
           if(a[i][j]=='#') continue;
           if(a[i][j+1]=='.') {adj[i-2][j-2].pb({i-2,j-1});edge[i-2][j-2][i-2][j-1]=1;}
           if(a[i][j-1]=='.') {adj[i-2][j-2].pb({i-2,j-3});edge[i-2][j-2][i-2][j-3]=1;}
           if(a[i-1][j]=='.') {adj[i-2][j-2].pb({i-3,j-2});edge[i-2][j-2][i-3][j-2]=1;}
           if(a[i+1][j]=='.') {adj[i-2][j-2].pb({i-1,j-2});edge[i-2][j-2][i-1][j-2]=1;} 
           
           for(ll i1=-2;i1<=2;i1++){
               for(ll j1=-2;j1<=2;j1++){
                   if(i1==0&&j1==0) continue;
                   if(abs(i1-j1)==1&&(i1*j1)==0) continue;
                   if(a[i+i1][j+j1]=='.'){
                       adj[i-2][j-2].pb({i-2+i1,j-2+j1});
                       edge[i-2][j-2][i-2+i1][j-2+j1]=2;
                   }
                   
               }
           }
       }
   }
   bfs(in1-1,in2-1,ou1-1,ou2-1);
   if(visit[ou1][ou2]==0) cout<<"-1";
   else{
       for(ll j=0;j<adj[ou1-1][ou2-1].size();j++){
         ans1=min(ans1,ans[adj[ou1-1][ou2-1][j].first][adj[ou1-1][ou2-1][j].second]);
       }
       cout<<ans1;
   }
    
  
}
    
return 0;    
}

Compiler output:
a.cc: In function 'void bfs(long long int, long long int, long long int, long long int)':
a.cc:27:33: error: reference to 'visit' is ambiguous
   27 |      for(ll j1=0;j1<10001;j1++){visit[i1][j1]=0;
      |                                 ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:21:4: note:                 'long long int visit [10001][10001]'
   21 | ll visit[10001][10001];
      |    ^~~~~
a.cc:42:17: error: reference to 'visit' is ambiguous
   42 |             if (visit[z.first][z.second]==0) {
      |                 ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:21:4: note:                 'long long int visit [10001][10001]'
   21 | ll visit[10001][10001];
      |    ^~~~~
a.cc:43:16: error: reference to 'visit' is ambiguous
   43 |                visit[z.first][z.second]=1;
      |                ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:21:4: note:                 'long long int visit [10001][10001]'
   21 | ll visit[10001][10001];
      |    ^~~~~
a.cc: In function 'int main()':
a.cc:85:7: error: reference to 'visit' is ambiguous
   85 |    if(visit[ou1][ou2]==0) cout<<"-1";
      |       ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:21:4: note:                 'long long int visit [10001][10001]'
   21 | ll visit[10001][10001];
      |    ^~~~~