C++ - Double BFS
Code\n\nclass Solution {\npublic:\n    static constexpr int drow[4] = {-1,0,1,0};\n    static constexpr int dcol[4] = {0,1,0,-1};\n    bool isPossible(int box_r
# Code\n```\nclass Solution {\npublic:\n    static constexpr int drow[4] = {-1,0,1,0};\n    static constexpr int dcol[4] = {0,1,0,-1};\n    bool isPossible(int box_row,int box_col,int dest_row,int dest_col,int row,int col,vector<vector<char>> &grid){\n        int n = grid.size(); int m = grid[0].size();\n        if(dest_row < 0 || dest_col < 0 || dest_row >=n || dest_col >=m || grid[dest_row][dest_col] == \'#\') return false;\n        vector<vector<int>> vis(grid.size(),vector<int> (grid[0].size(),0));\n        vis[row][col] = 1;\n        queue<pair<int,int>> q;\n        q.push({row,col});\n        while(!q.empty()){\n            auto it = q.front();\n            int r = it.first;\n            int c = it.second;\n            q.pop();\n            if(r == dest_row && c == dest_col) return true;\n            for(int i=0;i<4;i++){\n                int nrow = r + drow[i];\n                int ncol = c + dcol[i];\n                if(nrow >=0 && ncol>=0 && nrow < n && ncol < m && !vis[nrow][ncol] && grid[nrow][ncol] == \'.\'){\n                    if(nrow == box_row && ncol == box_col) continue;\n                    q.push({nrow,ncol});\n                    vis[nrow][ncol] = 1;\n                }\n            }\n        }\n        return false;\n    }\n    int minPushBox(vector<vector<char>>& grid) {\n        int n = grid.size(); int m = grid[0].size();\n        pair<int,int> target = {-1,-1};\n        pair<int,int> man = {-1,-1};\n        pair<int,int> block = {-1,-1};\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                if(grid[i][j] == \'T\') target = {i,j};\n                else if(grid[i][j] == \'B\') block = {i,j};\n                else if(grid[i][j] == \'S\') man = {i,j};\n                else continue;\n            }\n            if(target.first != -1 && man.first != -1 && block.first!=-1) break;\n        }\n        map<pair<int,int>,pair<int,int>> mpp;\n        mpp[{0,-1}] = {0,1};\n        mpp[{0,1}] = {0,-1};\n        mpp[{-1,0}] = {1,0};\n        mpp[{1,0}] = {-1,0};\n        grid[target.first][target.second] = \'.\';\n        grid[block.first][block.second] = \'.\';\n        grid[man.first][man.second] = \'.\';\n        queue<vector<int>> q; // {dis,block_row,block_col,man_row,man_col}\n        set<vector<int>> vis; // block,man\n        q.push({0,block.first,block.second,man.first,man.second});\n        while(!q.empty()){\n            auto it = q.front();\n            q.pop();\n            int dis = it[0];\n            int row = it[1];\n            int col = it[2];\n            int man_row = it[3];\n            int man_col = it[4];\n            if(row == target.first && col == target.second) return dis;\n            for(int i=0;i<4;i++){\n                int nrow = row + drow[i];\n                int ncol = col + dcol[i];\n                int opp_row = row + mpp[{drow[i],dcol[i]}].first;\n                int opp_col = col + mpp[{drow[i],dcol[i]}].second;\n                if(nrow >=0 && ncol >=0 && nrow < n && ncol < m && !vis.contains({nrow,ncol,row,col}) && grid[nrow][ncol] == \'.\' && isPossible(row,col,opp_row,opp_col,man_row,man_col,grid)){\n                    q.push({dis+1,nrow,ncol,row,col});\n                    vis.insert({nrow,ncol,row,col});\n                }\n            }\n        }\n        return -1;\n    }\n};\n```
['Breadth-First Search', 'Matrix', 'C++']