Language: C++

using namespace std;
#include <bits/stdc++.h>
#define frr(i, r, l) for(int i = r; i >= l; --i)
#define fr(i, l, r) for(int i = l; i < r; ++i)
#define forit(it, type, var) for(type::iterator it = var.begin(); it != var.end(); it++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define MEMS(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define m_p make_pair
#define pb push_back
#define ll long long
#define ld long double
typedef pair<ll, ll> iPair; 
priority_queue< ll, vector <ll> , greater<ll>>pq1,pq2;
#define maxN 1000000000000000000
ll power(ll a,ll b){ll res=1;while(b>0){res*=a;b--;}return res;}
ll mn[1005][1005],visit[1005][1005],n,m;
string str[2005];
queue<pair<ll,ll>>q;
ll bfs(ll a,ll b)
{
    visit[a][b]=1;
    q.push({a,b});
    mn[a][b]=0;

    while(!q.empty())
    {
        a=q.front().first;
        b=q.front().second;

        ll b1=b-2;
        if(b1<0)
        b1=0;

        ll b2=b+2;
        if(b2>m-1)
        b2=m-1;

        ll a1=a-2;
        if(a1<0)
        a1=0;

        ll a2=a+2;
        if(a2>n-1)
        a2=n-1;

        fr(i,a1,a2+1)
        {
            fr(j,b1,b2+1)
            {
                if(visit[i][j]==0 && str[i][j]=='.')
                {
                    q.push({i,j});
                    visit[i][j]=1;
                    if(abs(i-a)+abs(j-b)<=1)
                    {
                        mn[i][j]=min(mn[i][j],mn[a][b]);
                    }
                    else
                    {
                        mn[i][j]=min(mn[i][j],mn[a][b]+1);
                    }
                }
                else if(visit[i][j]==1 && str[i][j]=='.')
                {
                    if(abs(i-a)+abs(j-b)<=1)
                    {
                        mn[i][j]=min(mn[i][j],mn[a][b]);
                    }
                    else
                    {
                        mn[i][j]=min(mn[i][j],mn[a][b]+1);
                    }
                }
            }
        }
        q.pop();
    }
    return 0;
}
int main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll x1,y1,y2,x2;
    cin>>n>>m;
    cin>>x1>>y1;
    cin>>x2>>y2;

    fr(i,0,n)
    {
        cin>>str[i];
    }
    fr(i,0,n+1)
    {
        fr(j,0,m+1)
        {
            mn[i][j]=maxN;
        }
    }
    x1--;y1--;x2--;y2--;
    if(str[x1][y1]=='#')
    {
        cout<<"-1"<<endl;
        return 0;
    }
    bfs(x1,y1);
    if(mn[x2][y2]!=maxN)
    cout<<mn[x2][y2]<<endl;
    else
    cout<<"-1"<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'long long int bfs(long long int, long long int)':
a.cc:24:5: error: reference to 'visit' is ambiguous
   24 |     visit[a][b]=1;
      |     ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:2:
/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:19:19: note:                 'long long int visit [1005][1005]'
   19 | ll mn[1005][1005],visit[1005][1005],n,m;
      |                   ^~~~~
a.cc:53:20: error: reference to 'visit' is ambiguous
   53 |                 if(visit[i][j]==0 && str[i][j]=='.')
      |                    ^~~~~
/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:19:19: note:                 'long long int visit [1005][1005]'
   19 | ll mn[1005][1005],visit[1005][1005],n,m;
      |                   ^~~~~
a.cc:56:21: error: reference to 'visit' is ambiguous
   56 |                     visit[i][j]=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:19:19: note:                 'long long int visit [1005][1005]'
   19 | ll mn[1005][1005],visit[1005][1005],n,m;
      |                   ^~~~~
a.cc:66:25: error: reference to 'visit' is ambiguous
   66 |                 else if(visit[i][j]==1 && str[i][j]=='.')
      |                         ^~~~~
/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:19:19: note:                 'long long int visit [1005][1005]'
   19 | ll mn[1005][1005],visit[1005][1005],n,m;
      |                   ^~~~~