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<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 (auto x = adj[s.first][s.second].begin();x!= adj[s.first][s.second].end(); ++x) { 
            pll z=*x;
            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];
    }
  // ll adj
   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();i++){
           ans1=min(ans1,ans[adj[ou1-1][ou2-1].first][adj[ou1-1][ou2-1].first])
       }
       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:37:19: error: conversion from 'std::vector<std::pair<long long int, long long int> >' to non-scalar type 'std::pair<long long int, long long int>' requested
   37 |             pll z=*x;
      |                   ^~
a.cc:39:17: error: reference to 'visit' is ambiguous
   39 |             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:40:16: error: reference to 'visit' is ambiguous
   40 |                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:53:9: error: expected initializer before '.' token
   53 |     ll n.m;cin>>n>>m;
      |         ^
a.cc:53:17: error: 'n' was not declared in this scope
   53 |     ll n.m;cin>>n>>m;
      |                 ^
a.cc:53:20: error: 'm' was not declared in this scope
   53 |     ll n.m;cin>>n>>m;
      |                    ^
a.cc:58:36: error: 'a' was not declared in this scope
   58 |         for(ll j=2;j<m+2;j++) cin>>a[i][j];
      |                                    ^
a.cc:63:15: error: 'a' was not declared in this scope
   63 |            if(a[i][j]=='#') continue;
      |               ^
a.cc:64:15: error: 'a' was not declared in this scope
   64 |            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;}
      |               ^
a.cc:64:48: error: no matching function for call to 'std::vector<std::vector<std::pair<long long int, long long int> > >::push_back(<brace-enclosed initializer list>)'
   64 |            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;}
      |                                ~~~~~~~~~~~~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int> > >; value_type = std::vector<std::pair<long long int, long long int> >]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::vector<std::pair<long long int, long long int> > >::value_type&' {aka 'const std::vector<std::pair<long long int, long long int> >&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::vector<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int> > >; value_type = std::vector<std::pair<long long int, long long int> >]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::vector<std::pair<long long int, long long int> > >::value_type&&' {aka 'std::vector<std::pair<long long int, long long int> >&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:65:15: error: 'a' was not declared in this scope
   65 |            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;}
      |               ^
a.cc:65:48: error: no matching function for call to 'std::vector<std::vector<std::pair<long long int, long long int> > >::push_back(<brace-enclosed initializer list>)'
   65 |            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;}
      |                                ~~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int> > >; value_type = std::vector<std::pair<long long int, long long int> >]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::vector<std::pair<long long int, long long int> > >::value_type&' {aka 'const std::vector<std::pair<long long int, long long int> >&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::vector<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int> > >; value_type = std::vector<std::pair<long long int, long long int> >]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::vector<std::pair<long long int, long long int> > >::value_type&&' {aka 'std::vector<std::pair<long long int, long long int> >&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:66:15: error: 'a' was not declared in this scope
   66 |            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;}
      |               ^
a.cc:66:48: error: no matching function for call to 'std::vector<std::vector<std::pair<long long int, long long int> > >::push_back(<brace-enclosed initializer list>)'
   66 |            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;}
      |                                ~~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int> > >; value_type = std::vector<std::pair<long long int, long long int> >]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::vector<std::pair<long long int, long long int> > >::value_type&' {aka 'const std::vector<std::pair<long long int, long long int> >&'}
 1283 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1300:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(value_type&&) [with _Tp = std::vector<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int> > >; value_type = std::vector<std::pair<long long int, long long int> >]'
 1300 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1300:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::vector<std::pair<long long int, long long int> > >::value_type&&' {aka 'std::vector<std::pair<long long int, long long int> >&&'}
 1300 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
a.cc:67:15: error: 'a' was not declared in this scope
   67 |            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;}
      |               ^
a.cc:67:48: error: no matching function for call to 'std::vector<std::vector<std::pair<long long int, long long int> > >::push_back(<brace-enclosed initializer list>)'
   67 |            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;}
      |                                ~~~~~~~~~~~~~~~~^~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<std::pair<long long int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<long long int, long long int> > >; value_type = std::vector<std::pair<long long int, long long int> >]'
 1283 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1283:35: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::vector<std::vector<st