C++ Solution. Using Dijkstra's Algorithm
Intuition\nUse Dijkstra\'s Algorithm\n\n# Code\n\nclass Solution {\npublic:\n    // 0 - distance\n    // 1 - BoxX\n    // 2 - BoxY\n    // 3 - ManX\n    // 4 - 
# Intuition\nUse Dijkstra\'s Algorithm\n\n# Code\n```\nclass Solution {\npublic:\n    // 0 - distance\n    // 1 - BoxX\n    // 2 - BoxY\n    // 3 - ManX\n    // 4 - ManY\n\n    int dx[4] = {0, 0, -1, 1};\n    int dy[4] = {-1, 1, 0, 0};\n\n    bool isValid(int x, int y, int n, int m, vector<vector<char>> &grid){\n        if(x >= 0 && y >= 0 && x < n && y < m && grid[x][y] != \'#\'){\n            return true;\n        }\n        return false;\n    }\n\n    int minPushBox(vector<vector<char>>& grid) {\n        int n = grid.size(), m = grid[0].size();\n        priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> pq;\n        vector<int> init(5, 0);\n        for(int i = 0; i < n; i++){\n            for(int j = 0; j < m; j++){\n                if(grid[i][j] == \'B\'){\n                    init[1] = i;\n                    init[2] = j;\n                }\n                else if(grid[i][j] == \'S\'){\n                    init[3] = i;\n                    init[4] = j;\n                }\n            }\n        }\n\n        pq.push(init);\n        map<vector<int>, int> dist;\n        dist[{init[1], init[2], init[3], init[4]}] = 0;\n\n        while(!pq.empty()) {\n            int distance = pq.top()[0], boxX = pq.top()[1], boxY = pq.top()[2], manX = pq.top()[3], manY = pq.top()[4];\n            pq.pop();\n            // cout << "MAN: " << manX << " " << manY << "   BOX: " << boxX << " " << boxY << "\\n";\n\n            if(grid[boxX][boxY] == \'T\'){\n                return distance;\n            }\n\n            for(int i = 0; i < 4; i++){\n                if(isValid(manX + dx[i], manY + dy[i], n, m, grid)){\n                    if(manX + dx[i] == boxX && manY + dy[i] == boxY){\n                        if(isValid(boxX + dx[i], boxY + dy[i], n, m, grid) && (dist.find({boxX + dx[i], boxY + dy[i], manX + dx[i], manY + dy[i]}) == dist.end()) || (dist[{boxX + dx[i], boxY + dy[i], manX + dx[i], manY + dy[i]}] > distance + 1)) {\n                            if(manX + dx[i] == boxX + dx[i] && manY + dy[i] == boxY + dy[i]){\n                                cout << "hello\\n";\n                            }\n                            pq.push({distance + 1, boxX + dx[i], boxY + dy[i], manX + dx[i], manY + dy[i]});\n                            dist[{boxX + dx[i], boxY + dy[i], manX + dx[i], manY + dy[i]}] = distance + 1;\n                        }\n                    }\n                    else{\n                        if((dist.find({boxX, boxY, manX + dx[i], manY + dy[i]}) == dist.end()) || (dist[{boxX, boxY, manX + dx[i], manY + dy[i]}] > distance)) {\n                            pq.push({distance, boxX, boxY, manX + dx[i], manY + dy[i]});\n                            dist[{boxX, boxY, manX + dx[i], manY + dy[i]}] = distance;\n                        } \n                    }\n                }\n            }\n        }\n\n        return -1;\n    }\n};\n```
['Array', 'Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Matrix', 'Shortest Path', 'C++']