#include<stdio.h>
#include<iostream>
#define N 100
int map[N][N];
int visit[N][N];
struct que{
int *base;
int begin;
int end;
};
void initqueue(que q)
{
q.base=(int*)malloc(sizeof(int)*N);
q.begin=0;
q.end=0;
}
void push(que q,int value)
{
q.base[q.end]=value;
q.end=(q.end+1)%N;
}
int pop(que q)
{
int value;
value=q.base[q.begin];
q.begin=(q.begin+1)%N;
if(q.begin==q.end)printf("The queue is void");
return value;
}
int limit(int xt,int yt,int x,int y)
{
if(xt<0 || yt<0 || xt>x || yt>y)return 0;
return 1;
}
void bfs(que queue,int x,int y,int xb,int yb,int xe,int ye)
{
int xt,yt;
push(queue,xb);
push(queue,yb);
visit[xb][yb]=1;
while(1)
{
yt=pop(queue);
xt=pop(queue);
if(xt==xe && yt==ye)break;
if(limit(xt+1,yt,x,y)){push(queue,xt+1);push(queue,yt);visit[xt+1][yt]=1;}
if(limit(xt,yt+1,x,y)){push(queue,xt);push(queue,yt+1);visit[xt][yt+1]=1;}
if(limit(xt-1,yt,x,y)){push(queue,xt-1);push(queue,yt);visit[xt-1][yt]=1;}
if(limit(xt,yt-1,x,y)){push(queue,xt);push(queue,yt-1);visit[xt][yt-1]=1;}
}
}
int main()
{
que queue;
int x,y,i,k;
int xb,yb,xe,ye;
initqueue(queue);
scanf("%d%d",&x,&y);
scanf("%d%d",&xb,&yb);
scanf("%d%d",&xe,&ye);
for(i=0;i<x;i++)
for(k=0;k<y;k++)
scanf("%d",&map[i][k]);
for(i=0;i<x;i++)
for(k=0;k<y;k++)
visit[i][k]=0;
bfs(queue,x,y,xb,yb,xe,ye);
return 0;
}
#include<iostream>
#define N 100
int map[N][N];
int visit[N][N];
struct que{
int *base;
int begin;
int end;
};
void initqueue(que q)
{
q.base=(int*)malloc(sizeof(int)*N);
q.begin=0;
q.end=0;
}
void push(que q,int value)
{
q.base[q.end]=value;
q.end=(q.end+1)%N;
}
int pop(que q)
{
int value;
value=q.base[q.begin];
q.begin=(q.begin+1)%N;
if(q.begin==q.end)printf("The queue is void");
return value;
}
int limit(int xt,int yt,int x,int y)
{
if(xt<0 || yt<0 || xt>x || yt>y)return 0;
return 1;
}
void bfs(que queue,int x,int y,int xb,int yb,int xe,int ye)
{
int xt,yt;
push(queue,xb);
push(queue,yb);
visit[xb][yb]=1;
while(1)
{
yt=pop(queue);
xt=pop(queue);
if(xt==xe && yt==ye)break;
if(limit(xt+1,yt,x,y)){push(queue,xt+1);push(queue,yt);visit[xt+1][yt]=1;}
if(limit(xt,yt+1,x,y)){push(queue,xt);push(queue,yt+1);visit[xt][yt+1]=1;}
if(limit(xt-1,yt,x,y)){push(queue,xt-1);push(queue,yt);visit[xt-1][yt]=1;}
if(limit(xt,yt-1,x,y)){push(queue,xt);push(queue,yt-1);visit[xt][yt-1]=1;}
}
}
int main()
{
que queue;
int x,y,i,k;
int xb,yb,xe,ye;
initqueue(queue);
scanf("%d%d",&x,&y);
scanf("%d%d",&xb,&yb);
scanf("%d%d",&xe,&ye);
for(i=0;i<x;i++)
for(k=0;k<y;k++)
scanf("%d",&map[i][k]);
for(i=0;i<x;i++)
for(k=0;k<y;k++)
visit[i][k]=0;
bfs(queue,x,y,xb,yb,xe,ye);
return 0;
}