Language: C++

#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define inf 10000000LL
#define fast_io	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define range 1005
#define lg 22
using namespace std;
queue<pair<ll,ll> > mq;
queue<pair<pair<ll,ll> ,ll> >warpq,master;
ll visit[range][range];
ll A[range][range];
ll h,w;
ll dr[4]={0,0,-1,1};
ll dc[4]={1,-1,0,0};
void print()
{
				for(ll i=1;i<=h;i++)
	{
//		cin>>s;
		for(ll j=1;j<=w;j++)
		{
			cout<<visit[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<"\n\n";
}
void simple(ll c)
{
	ll x,y,rr,cc;
//	print();
	while(mq.size())
	{
		
		x=mq.front().ff;
		y=mq.front().ss;
		master.push(mp(mp(x,y),c));
		mq.pop();
//		cout<<x<<"	"<<y<<endl;
		if(visit[x][y]!=-1)
		continue;
		visit[x][y]=c;
		
		for(ll i=0;i<4;i++)
		{
			rr=dr[i]+x;
			cc=dc[i]+y;
			if(rr<1||rr>h||cc<1||cc>w)
			continue;
			if(A[rr][cc]=='#')
			continue;
//			cout<<"x"<<endl;
//			cout<<rr<<" "<<cc<<endl;
			if(visit[rr][cc]==-1)
				mq.push(mp(rr,cc));
					
			
		}
//		cout<<"\n";
	}
//	print();
}

void warp()
{
	ll x,y,rr,cc,c;
//	cout<<"warp begin:\n";
	while(master.size())
	{
		
		x=master.front().ff.ff;
		y=master.front().ff.ss;
		c=master.front().ss;
		
		master.pop();
//		cout<<x<<"	"<<y<<endl;
		for(ll i=-2;i<=2;i++)
		{
			for(ll j=-2;j<=2;j++)
			{
				
				rr=x+i;
				cc=y+j;
				if(rr<1||rr>h||cc<1||cc>w)
				continue;
				if(A[rr][cc]=='#')
				continue;
				if(visit[rr][cc]==-1)
				warpq.push(mp(mp(rr,cc),c+1));
			}
			
		}
	}
//		cout<<warpq.size()<<endl;
//		cout<<"warp end:\n";
		
}
void move(ll x,ll y)
{

	ll c,rr,cc;
	warpq.push(mp(mp(x,y),1));
	while(warpq.size())
	{
		
		x=warpq.front().ff.ff;
		y=warpq.front().ff.ss;
		c=warpq.front().ss;
//		cout<<x<<"	xx	"<<y<<endl;
		warpq.pop();

		if(visit[x][y]==-1)
		{
			mq.push(mp(x,y));
		simple(c);
		}

		if(warpq.size()==0)
		warp();		
	}
	
	
	
}
int main()
{
	ll x,y,p,q;
	memset(visit,-1,sizeof(visit));
	cin>>h>>w;
	cin>>x>>y;
	cin>>p>>q;
	string s;
	for(ll i=1;i<=h;i++)
	{
		cin>>s;
		for(ll j=1;j<=w;j++)
		{
			A[i][j]=s[j-1];
		}
	}
	move(x,y);
	if(visit[p][q]==-1)
	cout<<-1<<endl;
	else cout<<visit[p][q]-1<<endl;

}

Compiler output:
a.cc: In function 'void print()':
a.cc:27:31: error: reference to 'visit' is ambiguous
   27 |                         cout<<visit[i][j]<<" ";
      |                               ^~~~~
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:15:4: note:                 'long long int visit [1005][1005]'
   15 | ll visit[range][range];
      |    ^~~~~
a.cc: In function 'void simple(long long int)':
a.cc:45:20: error: reference to 'visit' is ambiguous
   45 |                 if(visit[x][y]!=-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:15:4: note:                 'long long int visit [1005][1005]'
   15 | ll visit[range][range];
      |    ^~~~~
a.cc:47:17: error: reference to 'visit' is ambiguous
   47 |                 visit[x][y]=c;
      |                 ^~~~~
/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:15:4: note:                 'long long int visit [1005][1005]'
   15 | ll visit[range][range];
      |    ^~~~~
a.cc:59:28: error: reference to 'visit' is ambiguous
   59 |                         if(visit[rr][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:15:4: note:                 'long long int visit [1005][1005]'
   15 | ll visit[range][range];
      |    ^~~~~
a.cc: In function 'void warp()':
a.cc:93:36: error: reference to 'visit' is ambiguous
   93 |                                 if(visit[rr][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:15:4: note:                 'long long int visit [1005][1005]'
   15 | ll visit[range][range];
      |    ^~~~~
a.cc: In function 'void move(long long int, long long int)':
a.cc:117:20: error: reference to 'visit' is ambiguous
  117 |                 if(visit[x][y]==-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:15:4: note:                 'long long int visit [1005][1005]'
   15 | ll visit[range][range];
      |    ^~~~~
a.cc: In function 'int main()':
a.cc:133:16: error: reference to 'visit' is ambiguous
  133 |         memset(visit,-1,sizeof(visit));
      |                ^~~~~
/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:15:4: note:                 'long long int visit [1005][1005]'
   15 | ll visit[range][range];
      |    ^~~~~
a.cc:133:32: error: reference to 'visit' is ambiguous
  133 |         memset(visit,-1,sizeof(visit));
      |                                ^~~~~
/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:15:4: note:                 'long long int visit [1005][1005]'
   15 | ll visit[range][range];
      |    ^~~~~
a.cc:147:12: error: reference to 'visit' is ambiguous
  147 |         if(visit[p][q]==-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:15:4: note:                 'long long int visit [1005][1005]'
   15 | ll visit[range][range];
      |    ^~~~~
a.cc:149:20: error: reference to 'visit' is ambiguous
  149 |         else cout<<visit[p][q]-1<<endl;
      |                    ^~~~~
/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:15:4: note:                 'long long int visit [1005][1005]'
   15 | ll visit[range][range];
      |    ^~~~~