Rt,BFS做的,除第一个点以外全部TLE
#include<bits/stdc++.h>
using namespace std;
bool vis[105][105];
char mp[105][105];
int n,m;
queue<pair<int,int> > q;
void bfs()
{
while(!q.empty())
{
pair t=q.front();
q.pop();
vis[t.first][t.second]=1;
if(t.first==n&&t.second==m)break;
mp[t.first][t.second]='#';
if(mp[t.first+1][t.second]=='.')q.push({t.first+1,t.second});
if(mp[t.first][t.second+1]=='.')q.push({t.first,t.second+1});
if(mp[t.first][t.second-1]=='.')q.push({t.first,t.second-1});
if(mp[t.first-1][t.second]=='.')q.push({t.first-1,t.second});
}
return;
}
int main()
{
cin >> n >> m;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
cin >> mp[i][j];
}
}
q.push({1,1});
bfs();
if(vis[n][m])cout << "Yes";
else cout << "No";
return 0;
}