请问蒟蒻的bfs怎么剪枝
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
bool zg[110][110]; //有没有走过
int mapp[110][110];
int dx[4]={-1,1,0,0};
int dy[4]={0,0,-1,1}; //辅助数组
int m,n;
struct node{
int x,y,coin;
bool flag; //上一步是否使用魔法
int color;
}walk;
queue<node> q;
int bfs(int fx,int fy){
int ans=1000000; //最小花费
q.push((node){fx,fy,0,false,mapp[fx][fy]});
zg[fx][fy]=true;
while(!q.empty())
{
walk=q.front();
q.pop();
zg[walk.x][walk.y]=true;
for(int i=0;i<4;i++)
{
int nx=walk.x+dx[i];
int ny=walk.y+dy[i];
int nc,ncolor; //走到下一个格子的花费和下一个格子的颜色
bool nf=false;
if((mapp[nx][ny]==-1&&walk.flag==true)||zg[nx][ny]==true||nx<1||nx>m||ny<1||ny>m)
continue;
if(mapp[nx][ny]==-1)
nc=2,nf=true,ncolor=mapp[walk.x][walk.y]; //下一个格子为无色
else if(mapp[nx][ny]!=walk.color)
nc=1,ncolor=mapp[nx][ny]; //下一个格子与当前格子颜色不同
else
nc=0,ncolor=walk.color; //颜色相同
if(nx==m&&ny==m)
{
ans=min(ans,walk.coin+nc);
continue;
}
q.push((node){nx,ny,walk.coin+nc,nf,ncolor});
}
}
if(ans==1000000)
return -1;
else
return ans;
}
int main(){
cin>>m>>n;
memset(mapp,-1,sizeof(mapp)); //-1代表无色
for(int i=1;i<=n;i++)
{
int x,y,c;
cin>>x>>y>>c;
mapp[x][y]=c;
}
if(m==1)
{
cout<<0;
return 0;
} //特判
int ans=bfs(1,1);
cout<<ans;
return 0;
}