https://www.luogu.com.cn/problem/B3625
#include<bits/stdc++.h>
#include<queue>
using namespace std;
string Map[100];
int MAP[100][100]={0};
int step[4][2]={{0,1},{1,0},{0,-1},{-1,0}};
int m,n;
bool flag=false;
int main()
{
cin>>n>>m;
for (int i = 0; i < n; ++i) {
cin>>Map[i];
}
int x=0,y=0;
queue<int> qx,qy;
MAP[0][0]=1;
qx.push(x);
qy.push(y);
while (!qx.empty()){
int X=qx.front(),Y=qy.front();
qx.pop();
qy.pop();
for (int i = 0; i < 4; ++i) {
int newX=X+step[i][0];
int newY=Y+step[i][1];
if (newX>=0&&newX<n&&newY>=0&&newY<m&&MAP[newX][newY]==0&&Map[newX][newY]!='#') {
MAP[newX][newY] = 1;
qx.push(newX);
qy.push(newY);
if (newX == n - 1 && newY == m - 1) {
flag=true;
break;
}
}
}
if (flag) break;
}
if (flag){
cout<<"Yes";
}
else{
cout<<"No";
}
return 0;
}