func_code_string: #include <bits/stdc++.h>   using namespace std;   int dx[] = {1, -1, 0, 0};   int dy[] = {0, 0, -1, 1};   int n, m;   char grid[1005][1005];   int startX, startY, endX, endY;   int cost[1005][1005];   int lookDir[1005][1005];   bool vis[1005][1005];   bool isValid(int i, int j) {     return i >= 0 && i < n && j >= 0 && j < m && grid[i][j] !=  * ;   }   void bfs() {     queue<pair<int, int> > q;     q.push({startX, startY});     cost[startX][startY] = 0;     lookDir[startX][startY] = 4;     vis[startX][startY] = 1;     while (q.size()) {       int x = q.front().first;       int y = q.front().second;       q.pop();       for (int i = 0; i < 4; i++) {         int xx = x + dx[i], yy = y + dy[i];         if (isValid(xx, yy) && (!vis[xx][yy] || cost[x][y] + 1 <= cost[xx][yy])) {           if (lookDir[x][y] == 4) {             if (dx[i] == 1) lookDir[xx][yy] = 3;             if (dx[i] == -1) lookDir[xx][yy] = 1;             if (dy[i] == 1) lookDir[xx][yy] = 2;             if (dy[i] == -1) lookDir[xx][yy] = 0;           } else if (lookDir[x][y] == 3 || lookDir[x][y] == 1) {             if (dy[i] != 0) cost[xx][yy] = cost[x][y] + 1;             if (dy[i] == -1) lookDir[xx][yy] = 0;             if (dy[i] == 1) lookDir[xx][yy] = 2;             if (dy[i] == 0)               lookDir[xx][yy] = lookDir[x][y], cost[xx][yy] = cost[x][y];           } else if (lookDir[x][y] == 0 || lookDir[x][y] == 2) {             if (dx[i] != 0) cost[xx][yy] = cost[x][y] + 1;             if (dx[i] == -1) lookDir[xx][yy] = 1;             if (dx[i] == 1) lookDir[xx][yy] = 3;             if (dx[i] == 0)               lookDir[xx][yy] = lookDir[x][y], cost[xx][yy] = cost[x][y];           }           vis[xx][yy] = 1;           q.push({xx, yy});         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++)       for (int j = 0; j < m; j++) {         cin >> grid[i][j];         if (grid[i][j] ==  S ) startX = i, startY = j;         if (grid[i][j] ==  T ) endX = i, endY = j;       }     bfs();     if (cost[endX][endY] <= 2 && vis[endX][endY])       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }   