Language: C++

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iomanip>
#include<limits.h>
#include<climits>
#include<queue>
using namespace std;
const int M=1e4*2;
char s[M][M];
int n,m,tot;
int s_x,s_y,t_x,t_y,ans;
int dis[M],d[M][M];
bool b[M][M],vis[M];
struct edge{
	int v,w;
	edge(){}
	edge(int V,int W){
		v=V;w=W;
	}
};
struct node{
	int u,dis;
	node(){}
	node(int U,int D){
		u=U;dis=D;
	}
	friend bool operator < (node a,node b){return a.dis>b.dis;}
};
priority_queue<node>Q;
vector<edge> G[M];
void add(int U,int V,int W){
	G[U].push_back(edge(V,W));
	G[V].push_back(edge(U,W));
}
int Dijkstra(int S){
	memset(vis,0,sizeof(vis));
	memset(dis,0x3f,sizeof(dis));
	dis[S]=0,Q.push(node(S,0));
	while(!Q.empty()){
		int u=Q.top().u;
		Q.pop();
		if(vis[u])
			continue;
		int v,w,siz=G[u].size();
		for(int i=0;i<siz;i++){
			v=G[u][i].v,w=G[u][i].w;
			if(dis[v]>dis[u]+w){
				dis[v]=dis[u]+w;
				Q.push(node(v,dis[v]));
			}
		}
	}
	return dis[d[t_x][t_y]];
}
void dfs(int x,int y){
	if(x<=0||x>n||y<=0||y>m||s[x][y]=='#'||d[x][y]) return;
	d[x][y]=tot;
	dfs(x+1,y);dfs(x-1,y);dfs(x,y+1);dfs(x,y-1);
	return ;
}
int main(){
		scanf("%d %d",&n,&m);
		scanf("%d %d",&s_x,&s_y);
		scanf("%d %d",&t_x,&t_y);
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				cin>>s[i][j];
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(s[i][j]=='.'&&!d[i][j]){
					tot++;
					dfs(i,j);
				}
			}
		}
		if(d[s_x][s_y]==d[t_x][t_y]) {
			printf("0");return 0;
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(s[i][j]=='.'){
					for(int l=i-2;l<=i+2;l++){
						for(int r=j-2;r<=j+2;r++){
							if(l<=0||l>n||r<=0||r>m||s[l][r]=='#'||d[l][r]==d[i][j]||b[d[l][r]][d[i][j]]){
								continue;
							}
							b[d[l][r]][d[i][j]]=1;b[d[i][j]][d[l][r]]=1;
							add(d[l][r],d[i][j],1);add(d[i][j],d[l][r],1);
						}
					}
				}
				
			}
		}
	/*	for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				printf("%d ",d[i][j]);
			}
			printf("\n");
		}
		for(int i=1;i<=tot;i++){
			for(int j=1;j<=tot;j++){
				printf("%d ",b[i][j]);
			}
			printf("\n");
		}*/
		int ans=Dijkstra(d[s_x][s_y]);
		if(ans==0x3f3f3f3f) printf("-1");
		else printf("%d",ans);
	return 0;
}



Compiler output:
/tmp/ccXHYell.o: in function `add(int, int, int)':
a.cc:(.text+0x28): relocation truncated to fit: R_X86_64_PC32 against symbol `G' defined in .bss section in /tmp/ccXHYell.o
a.cc:(.text+0x69): relocation truncated to fit: R_X86_64_PC32 against symbol `G' defined in .bss section in /tmp/ccXHYell.o
/tmp/ccXHYell.o: in function `Dijkstra(int)':
a.cc:(.text+0xb3): relocation truncated to fit: R_X86_64_PC32 against symbol `vis' defined in .bss section in /tmp/ccXHYell.o
a.cc:(.text+0x113): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/ccXHYell.o
a.cc:(.text+0x127): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/ccXHYell.o
a.cc:(.text+0x13b): relocation truncated to fit: R_X86_64_PC32 against symbol `Q' defined in .bss section in /tmp/ccXHYell.o
a.cc:(.text+0x14f): relocation truncated to fit: R_X86_64_PC32 against symbol `vis' defined in .bss section in /tmp/ccXHYell.o
a.cc:(.text+0x176): relocation truncated to fit: R_X86_64_PC32 against symbol `G' defined in .bss section in /tmp/ccXHYell.o
a.cc:(.text+0x1aa): relocation truncated to fit: R_X86_64_PC32 against symbol `G' defined in .bss section in /tmp/ccXHYell.o
a.cc:(.text+0x1dc): relocation truncated to fit: R_X86_64_PC32 against symbol `G' defined in .bss section in /tmp/ccXHYell.o
a.cc:(.text+0x296): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status