Language: C++

#include<bits/stdc++.h>
using namespace std;
int a,b,k,x1,y_1,x2,y2,d[500005],v[1005][1005];
bool f[500005][500005],n[1005][1005],vi[500005];
char c;
struct st{
	int w,v;
	st(int V,int W){
		w=W;
		v=V;
	}
};
struct st1{
	int w,dd;
	st1(){}
	st1(int W,int DD){
		w=W;
		dd=DD;
	}
	friend bool operator < (st1 x,st1 y){return x.dd>y.dd;}
};
priority_queue<st1>q;
vector<st> ans[2505];
int Dijkstra(int s,int t){
	memset(d,0x3f,sizeof(d));
	memset(vi,0,sizeof(vi));
	d[s]=0;
	q.push(st1(s,0));
	while(q.size()){
		int x=q.top().w;
		q.pop();
		if(vi[x]){
			continue;
		} 
		vi[x]=1;
		int siz=ans[x].size();
		for(int i=0;i<siz;i++){
			int vr=ans[x][i].v,w=ans[x][i].w;
			if(d[vr]>d[x]+w){
				d[vr]=d[x]+w;
				q.push(st1(vr,d[vr]));
			}
		}
	}
	return d[t];
}
void dfs(int x,int y){
	if(x>1&&v[x-1][y]==0&&n[x-1][y]==0){
		n[x-1][y]=1;
		v[x-1][y]=k;
		dfs(x-1,y);
		n[x-1][y]=0;
	}
	if(x<a&&v[x+1][y]==0&&n[x+1][y]==0){
		n[x+1][y]=1;
		v[x+1][y]=k;
		dfs(x+1,y);
		n[x+1][y]=0;
	}
	if(y>1&&v[x][y-1]==0&&n[x][y-1]==0){
		n[x][y-1]=1;
		v[x][y-1]=k;
		dfs(x,y-1);
		n[x][y-1]=0;
	}
	if(y<b&&v[x][y+1]==0&&n[x][y+1]==0){
		n[x][y+1]=1;
		v[x][y+1]=k;
		dfs(x,y+1);
		n[x][y+1]=0;
	}
}
int main(){
	scanf("%d %d\n",&a,&b);
	scanf("%d %d\n",&x2,&y2);
	scanf("%d %d",&x1,&y_1);
	for(int i=1;i<=a;i++){
		scanf("\n");
		for(int j=1;j<=b;j++){
			scanf("%c",&c);
			if(c=='#')n[i][j]=1;
		}
	}
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			if(v[i][j]==0&&n[i][j]==0){
				k++;
				v[i][j]=k;
				n[i][j]=1;
				dfs(i,j);
				n[i][j]=0;
			}
		}
	}
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			for(int i1=max(1,i-2);i1<=min(a,i+2);i1++){
				for(int j1=max(1,j-2);j1<=min(b,j+2);j1++){
					if(v[i][j]!=0&&v[i1][j1]!=0&&v[i][j]!=v[i1][j1]){
						ans[v[i][j]].push_back(st(v[i1][j1],1));
						ans[v[i1][j1]].push_back(st(v[i][j],1));
					}
				}
			}
		}
	}
	if(Dijkstra(v[x1][y_1],v[x2][y2])==0x3f3f3f3f){
		printf("-1");
	}else printf("%d",Dijkstra(v[x1][y_1],v[x2][y2]));
	
}

Compiler output:
/tmp/ccqVHnhw.o: in function `Dijkstra(int, int)':
a.cc:(.text+0x34): relocation truncated to fit: R_X86_64_PC32 against symbol `vi' defined in .bss section in /tmp/ccqVHnhw.o
a.cc:(.text+0x7b): relocation truncated to fit: R_X86_64_PC32 against symbol `q' defined in .bss section in /tmp/ccqVHnhw.o
a.cc:(.text+0x8f): relocation truncated to fit: R_X86_64_PC32 against symbol `q' defined in .bss section in /tmp/ccqVHnhw.o
a.cc:(.text+0xa3): relocation truncated to fit: R_X86_64_PC32 against symbol `q' defined in .bss section in /tmp/ccqVHnhw.o
a.cc:(.text+0xb7): relocation truncated to fit: R_X86_64_PC32 against symbol `vi' defined in .bss section in /tmp/ccqVHnhw.o
a.cc:(.text+0xd0): relocation truncated to fit: R_X86_64_PC32 against symbol `vi' defined in .bss section in /tmp/ccqVHnhw.o
a.cc:(.text+0xee): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccqVHnhw.o
a.cc:(.text+0x122): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccqVHnhw.o
a.cc:(.text+0x155): relocation truncated to fit: R_X86_64_PC32 against symbol `ans' defined in .bss section in /tmp/ccqVHnhw.o
a.cc:(.text+0x20e): relocation truncated to fit: R_X86_64_PC32 against symbol `q' defined in .bss section in /tmp/ccqVHnhw.o
a.cc:(.text+0x22d): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status