@[mmy129](/user/613598) 这不$0$分??
by s_c_lmlm_L @ 2022-08-16 16:19:16
```
#include<iostream>
#include<queue>
using namespace std;
struct Pos
{
int x,y;
};
queue <Pos> q;
int n,x,y,tx,ty,dis[1001][1001],s_a,s_b,t_a,t_b;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
char mp[1001][1001];
bool vis[1001][1001];
int bfs(int sx,int sy)
{
q.push((Pos){sx,sy});
vis[sx][sy]=true;
while(!q.empty())
{
x=q.front().x;
y=q.front().y;
q.pop();
if(x==t_a&&y==t_b) return dis[x][y];
for(int i=0;i<4;i++)
{
tx=x+dx[i];
ty=y+dy[i];
if(tx<=0||tx>n||ty<=0||ty>n) continue;
if(mp[tx][ty]=='1'||vis[tx][ty]==true) continue;
dis[tx][ty]=dis[x][y]+1;
vis[tx][ty]=true;
q.push((Pos){tx,ty});
}
}
return -1;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>mp[i][j];
cin>>s_a>>s_b>>t_a>>t_b;
cout<<bfs(s_a,s_b);
return 0;
}
```
by _Glassy_Sky_ @ 2022-08-16 16:32:10