Language: C++

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
#define all(a) a.begin(),a.end()
using namespace std;
const int dx[4]={1,-1,0,0};
const int dy[4]={0,0,1,-1};
const int DX[25]={0,0,0,0,0,1,1,1,1,1,2,2,2,2,2,-1,-1,-1,-1,-1,-2,-2,-2,-2,-2};
const int DY[25]={-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2,-2,-1,0,1,2};
int n,m;
int x,y,enx,eny,goal;
bool g[1005][1005];
int graph[1005][1005];
bool vis[1005][1005],visit[500005];
vpii ver[500005];
int dis[500005]={0};
int k=0;
ll ans=0;
map<pii,bool>reach;
bool infield(int a,int b){
	return a>=0&&b>=0&&a<n&&b<m;
}
void bfs1(int a,int b){
	queue<pii >q;
	q.push(mp(a,b));
	while(!q.empty()){
		int _x=q.front().fi,_y=q.front().se;
		q.pop();
		vis[_x][_y]=1;
		graph[_x][_y]=k;
		ver[k].pb(mp(_x,_y));
		REP(i,4){
			if((!vis[_x+dx[i]][_y+dy[i]])&&g[_x+dx[i]][_y+dy[i]]&&infield(_x+dx[i],_y+dy[i])){
				vis[_x+dx[i]][_y+dy[i]]=1;
				q.push(mp(_x+dx[i],_y+dy[i]));
			}
		}
	}
}
bool bfs2(int pos){
	queue<int>q;
	visit[pos]=1;
	q.push(pos);
	while(!q.empty()){
		int a=q.front();
		q.pop();
		REP(i,ver[a].size()){
			int _x=ver[a][i].fi,_y=ver[a][i].se;
			REP(j,25){
				if(g[_x+DX[j]][_y+DY[j]]&&infield(_x+DX[j],_y+DY[j])){
					if(graph[_x+DX[j]][_y+DY[j]]!=a&&!visit[graph[_x+DX[j]][_y+DY[j]]]){
						q.push(graph[_x+DX[j]][_y+DY[j]]);
						visit[graph[_x+DX[j]][_y+DY[j]]]=1;
						dis[graph[_x+DX[j]][_y+DY[j]]]=dis[a]+1;
					}
				}
			}
		}
	}
}
int main(void){
	cin>>n>>m>>x>>y>>enx>>eny;
	x--,y--,enx--,eny--;
	REP(i,n)REP(j,m)graph[i][j]=-1;
	REP(i,n)REP(j,m){
		char c;
		cin>>c;
		if(c=='.'){
			g[i][j]=1;
		} 
		else{
			g[i][j]=0;
		}
	}
	REP(i,n)REP(j,m){
		if(!vis[i][j]&&g[i][j]){
			bfs1(i,j);
			k++;
		}
	}
	memset(vis,false,sizeof(vis));
	goal=graph[enx][eny];
	if(goal==graph[x][y]){
		cout<<0;
		return 0;
	}
	bfs2(graph[x][y]);
	if(dis[goal]==0)cout<<-1;
	else cout<<dis[goal];
	return 0;
}

Compiler output:
a.cc: In function 'bool bfs2(int)':
a.cc:52:9: error: reference to 'visit' is ambiguous
   52 |         visit[pos]=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:24:22: note:                 'bool visit [500005]'
   24 | bool vis[1005][1005],visit[500005];
      |                      ^~~~~
a.cc:61:75: error: reference to 'visit' is ambiguous
   61 |                                         if(graph[_x+DX[j]][_y+DY[j]]!=a&&!visit[graph[_x+DX[j]][_y+DY[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:24:22: note:                 'bool visit [500005]'
   24 | bool vis[1005][1005],visit[500005];
      |                      ^~~~~
a.cc:63:49: error: reference to 'visit' is ambiguous
   63 |                                                 visit[graph[_x+DX[j]][_y+DY[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:24:22: note:                 'bool visit [500005]'
   24 | bool vis[1005][1005],visit[500005];
      |                      ^~~~~
a.cc:70:1: warning: no return statement in function returning non-void [-Wreturn-type]
   70 | }
      | ^