//新生训练
cpp
#include <bits/stdc++.h>
using namespace std;
int n, m;
bool f;
char mp[15][15];
int vis[15][15];
int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
bool in(int x, int y)
{
return 0 <= x && x < n && 0 <= y && y < m;
}
void dfs(int x, int y)
{
if (mp[x][y] == 'T')
{
f = true;
return;
}
if (!in(x, y) || mp[x][y] == '*' || vis[x][y])
{
return;
}
vis[x][y] = 1;
for (int i = 0; i < 4; i++)
{
int tx = x + dir[i][0];
int ty = y + dir[i][1];
dfs(tx, ty);
}
return;
}
int main()
{
cin >> n >> m ;
for (int i = 0; i < n; i++)
{
cin >> mp[i];
}
int x, y;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (mp[i][j] == 'S')
{
x = i;
y = j;
}
}
}
dfs(x, y);
if (f)
{
cout << "yes" << endl;
}
else
{
cout << "no" << endl;
}
return 0;
}
//笔者新学的DFS和BFS,练习了一些入门题目;
~~~//仅当笔者个人备忘录使用。