Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("It's Just Begining.Wait For The End!!!!!\n")
#define CHECK(x) cout << (#x) << " is " << (x) <<"\n";
#define endl printf("\n")
typedef pair<ll,ll> pii;
#define pb push_back
#define ms(a,b) memset(a, b, sizeof(a))
#define in(x) scanf("%lld",&x)
#define out(x) printf("%lld",x)
#define X first
#define Y second
#define sps printf(" ")
#define dou(x) cout<<fixed<<setprecision(6)<<x
#define all(v) v.begin(),v.end()
#define dis(it,it1) distance(it,it1)+1
#define MAX 1005
#define INF 1000000000
#define MOD 1000000007
#define print(cs) printf("Case %lld: ",cs)
#define Yesno(ok) if(ok)puts("YES");else puts("NO")
#define yesno(ok) if(ok)puts("Yes");else puts("No")
ll lcm(ll a,ll b)
{
    return ((a*b)/__gcd(a,b));
}
ll visit[MAX][MAX];
ll cost[MAX][MAX];
char lolo[MAX][MAX];
ll dx[]={0,0,1,-1};
ll dy[]={1,-1,0,0};
ll dd[]={0,0,0,0,1,1,1,1,1,-1,-1,-1,-1,-1,2,2,2,2,2,-2,-2,-2,-2,-2};
ll ee[]={1,-1,2,-2,1,-1,2,-2,0,1,-1,2,-2,0,1,-1,2,-2,0,1,-1,2,-2,0};
bool valid(ll xx,ll yy,ll n,ll m)
{
    if(xx>=1&&xx<=n&&yy>=1&&yy<=m&&lolo[xx][yy]!='#')return true;
    else return false;
}
void bfs(ll xx,ll yy,ll n,ll m)
{
    queue< pii >qq;
    qq.push({xx,yy});
    cost[xx][yy]=0;
    visit[xx][yy]=1;
    while(!qq.empty())
    {
        pii sorce=qq.front();
        qq.pop();
        for(ll i=0;i<4;i++)
        {
            xx=sorce.X+dx[i];
            yy=sorce.Y+dy[i];
            if(valid(xx,yy,n,m))
            {
                cost[xx][yy]=min(cost[sorce.X][sorce.Y],cost[xx][yy]);
                if(!visit[xx][yy]){
                qq.push({xx,yy});
                visit[xx][yy]=1;}
            }
        }
        for(ll i=0;i<24;i++)
        {
            xx=sorce.X+dd[i];
            yy=sorce.Y+ee[i];
            if(valid(xx,yy,n,m))
            {
                cost[xx][yy]=min(cost[sorce.X][sorce.Y]+1,cost[xx][yy]);
                if(!visit[xx][yy]){
                qq.push({xx,yy});
                visit[xx][yy]=1;}
            }
        }
    }
}
int main()
{
    ll test=1;
    while(test--)
    {
        ll i,j,k,l,n,m,r;
        in(n);in(m);
        in(l);in(r);
        ll de,dw;
        in(de);in(dw);
        for(i=1;i<=n;i++)
            for(j=1;j<=m;j++)cin>>lolo[i][j],cost[i][j]=INF;
        ms(visit,0);
        bfs(l,r,n,m);
        ll ans=(cost[de][dw]<INF?cost[de][dw]:-1);
        out(ans);endl;
    }
}


Compiler output:
a.cc: In function 'void bfs(long long int, long long int, long long int, long long int)':
a.cc:45:5: error: reference to 'visit' is ambiguous
   45 |     visit[xx][yy]=1;
      |     ^~~~~
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:28:4: note:                 'long long int visit [1005][1005]'
   28 | ll visit[MAX][MAX];
      |    ^~~~~
a.cc:57:21: error: reference to 'visit' is ambiguous
   57 |                 if(!visit[xx][yy]){
      |                     ^~~~~
/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:28:4: note:                 'long long int visit [1005][1005]'
   28 | ll visit[MAX][MAX];
      |    ^~~~~
a.cc:59:17: error: reference to 'visit' is ambiguous
   59 |                 visit[xx][yy]=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:28:4: note:                 'long long int visit [1005][1005]'
   28 | ll visit[MAX][MAX];
      |    ^~~~~
a.cc:69:21: error: reference to 'visit' is ambiguous
   69 |                 if(!visit[xx][yy]){
      |                     ^~~~~
/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:28:4: note:                 'long long int visit [1005][1005]'
   28 | ll visit[MAX][MAX];
      |    ^~~~~
a.cc:71:17: error: reference to 'visit' is ambiguous
   71 |                 visit[xx][yy]=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:28:4: note:                 'long long int visit [1005][1005]'
   28 | ll visit[MAX][MAX];
      |    ^~~~~
a.cc: In function 'int main()':
a.cc:88:12: error: reference to 'visit' is ambiguous
   88 |         ms(visit,0);
      |            ^~~~~
a.cc:9:24: note: in definition of macro 'ms'
    9 | #define ms(a,b) memset(a, b, sizeof(a))
      |                        ^
/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:28:4: note:                 'long long int visit [1005][1005]'
   28 | ll visit[MAX][MAX];
      |    ^~~~~
a.cc:88:12: error: reference to 'visit' is ambiguous
   88 |         ms(visit,0);
      |            ^~~~~
a.cc:9:37: note: in definition of macro 'ms'
    9 | #define ms(a,b) memset(a, b, sizeof(a))
      |                                     ^
/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:28:4: note:                 'long long int visit [1005][1005]'
   28 | ll visit[MAX][MAX];
      |    ^~~~~