MLE求助,怎么样才不会MLE
#include<bits/stdc++.h>
using namespace std;
int n,a1,b1,a2,b2;
bool mapp[1005][1005];
queue<int>qx;
queue<int>qy;
queue<int>qz;
int bfs(){
qx.push(a1);
qy.push(b1);
qz.push(0);
int i=0;
while(qx.empty()==0){
int x=qx.front();
int y=qy.front();
int z=qz.front();
qx.pop();
qy.pop();
qz.pop();
if(x==a2&&y==b2){
return z;
}
if(mapp[x+1][y]){
qx.push(x+1);
qy.push(y);
qz.push(z+1);
}
if(mapp[x][y+1]){
qx.push(x);
qy.push(y+1);
qz.push(z+1);
}
if(mapp[x-1][y]){
qx.push(x-1);
qy.push(y);
qz.push(z+1);
}
if(mapp[x][y-1]){
qx.push(x);
qy.push(y-1);
qz.push(z+1);
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
char c;
cin>>c;
mapp[i][j]=c-'0';
mapp[i][j]=!mapp[i][j];
}
}
cin>>a1>>b1>>a2>>b2;
cout<<bfs();
return 0;
}
//唱跳rap打篮球