A* short C++ version
https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/solutions/431061/a-star-search/\n\n# Code\n\nstruct Node {\n    int playerX, 
https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/solutions/431061/a-star-search/\n\n# Code\n```\nstruct Node {\n    int playerX, playerY;\n    int boxX, boxY;\n    int g, h, f; // f = g + h\n\n    bool operator < (const Node& n) const {\n        return n.f < f;\n    }\n};\n\nclass Solution {\npublic:\n    vector<pair<int, int>> dirs{{0, -1}, {0, 1}, {-1, 0}, {1, 0}};\n    int heuristic(Node& src, Node& dst) {\n        return abs(src.boxX - dst.boxX) + abs(src.boxY - dst.boxY);\n    }\n    bool isValid(vector<vector<char>>& grid, int i, int j) {\n        return i >= 0 && j >= 0 && i < grid.size() && j < grid[0].size() && grid[i][j] != \'#\';\n    }\n    int minPushBox(vector<vector<char>>& grid) {\n        int m = grid.size(), n = grid[0].size();\n        Node src, dst;\n        for (int i = 0; i < m; i++) {\n            for (int j = 0; j < n; j++) {\n                if (grid[i][j] == \'S\') {\n                    src.playerX = i;\n                    src.playerY = j;\n                }\n                if (grid[i][j] == \'B\') {\n                    src.boxX = i;\n                    src.boxY = j;\n                }\n                if (grid[i][j] == \'T\') {\n                    dst.boxX = i;\n                    dst.boxY = j;\n                }\n            }\n        }\n\n        src.g = 0;\n        src.h = heuristic(src, dst);\n        src.f = src.g + src.h;\n\n        priority_queue<Node> pq;\n        pq.push(src);\n        set<vector<int>> visited;\n        \n\n        while (!pq.empty()) {\n            Node curr = pq.top();\n            pq.pop();\n\n            if (curr.boxX == dst.boxX && curr.boxY == dst.boxY)\n                return curr.g;\n            if (visited.count({curr.playerX, curr.playerY, curr.boxX, curr.boxY}))\n                continue;\n            visited.insert({curr.playerX, curr.playerY, curr.boxX, curr.boxY});\n\n            for (auto& [dx, dy] : dirs) {\n                Node next = curr;\n                next.playerX = curr.playerX + dx;\n                next.playerY = curr.playerY + dy;\n\n                if (!isValid(grid, next.playerX, next.playerY))\n                    continue;\n                \n                if (next.playerX == curr.boxX && next.playerY == curr.boxY) {\n                    next.boxX = curr.boxX + dx;\n                    next.boxY = curr.boxY + dy;\n                    if (!isValid(grid, next.boxX, next.boxY))\n                        continue;\n                    \n                    next.g = curr.g + 1;\n                    next.h = heuristic(next, dst);\n                    next.f = next.g + next.h;\n                }\n                pq.push(next);\n            }\n        }\n        return -1;\n    }\n};\n```
['C++']