```cpp
#include<iostream>
#include<queue>
using namespace std;
int n,x1,y1,x2,y2;
char aa[1005][1005];
bool bb[1005][1005];
int xx[4]={0,1,0,-1};
int yy[4]={1,0,-1,0};
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>aa[i][j];
}
}
cin>>x1>>y1>>x2>>y2;
queue<int>q,q1,q2;
q.push(x1);
q1.push(y1);
q2.push(0);
bb[x1][y1] = 1;//这里
while(!q.empty())
{
if(q.front()==x2&&q1.front()==y2)
{
cout<<q2.front();
break;
}
else
{
for(int i=0;i<4;i++)
{
int nx=xx[i]+q.front();
int ny=yy[i]+q1.front();
if(nx>=1&&nx<=n&&ny>=1&&ny<=n&&aa[nx][ny]=='0'&&bb[nx][ny]==0)
{
q.push(nx),q1.push(ny),q2.push(q2.front()+1);
bb[nx][ny] = 1;//这里
}
}
q.pop();
q1.pop();
q2.pop();
}
}
return 0;
}
```
[AC记录](https://www.luogu.com.cn/record/69441160)
先将x1, y1 标记后在搜索
by DESTRUCTION_3_2_1 @ 2022-02-15 18:39:58
~~评测记录好壮观~~
by DESTRUCTION_3_2_1 @ 2022-02-15 18:43:22
@[Dyc大大吖](/user/537520) 谢谢大佬
by Cc_sir @ 2022-02-15 20:10:13