9MLE+1WA!

P1746 离开中山路

不写vis数组的危害,本人亲测((( @[Algorithm_ZRF](/user/1044048)
by The_Chariot @ 2024-02-01 17:40:24


@[Algorithm_ZRF](/user/1044048) 还有我没看懂你这个BFS,其实这就一BFS板子题,不用那么复杂,读入也正常读入就可以,下附核心代码: ```cpp queue<node>q; void bfs() { node now,next; vis[sx][sy]=1; now.x=sx,now.y=sy,now.step=0; q.push(now); while(!q.empty()) { now=q.front(); q.pop(); for(int i=0;i<4;++i) { next.x=now.x+dirx[i],next.y=now.y+diry[i],next.step=now.step+1; if(next.x==ex&&next.y==ey) { ans=next.step; return ; } if(next.x>0&&next.y>0&&next.x<=n&&next.y<=n&&mapp[next.x][next.y]=='0'&&vis[next.x][next.y]==0) { vis[next.x][next.y]=1; q.push(next); } } } } ```
by The_Chariot @ 2024-02-01 17:47:06


@[The_Chariot](/user/696391) 我用双向BFS做的
by Algorithm_ZRF @ 2024-02-01 18:00:46


@[The_Chariot](/user/696391) 而且mp就是我的vis啊
by Algorithm_ZRF @ 2024-02-01 18:04:18


|