BFS
登录以参加训练计划
struct node{
int x,y;
};
queue <node> q;
void bfs(){
node a={1,1};
vis[1][1]=1;
q.push(a);
while( q.empty()!=1 ){
node f=q.front();
if(mp[f.x][f.y]== ){
cout<<"YES";
return;
}
for(int i=0; i<4; i++){
int nx = f.x + dx[i], ny = f.y + dy[i];
if (nx>0&& nx<=n&& ny>0&&ny<=m&&mp[nx][ny]!=0&&vis[nx][ny]==0) {
vis[nx][ny]=1;
node r={nx,ny};
q.push(r);
}
}
q.pop( );
}
cout<<"NO";}
- 参加人数
- 12
- 创建人