C++ solution | 0-1 BFS
\nstatic bool fast = []()\n{\n    std::cin.tie(0)->sync_with_stdio(false);\n    return true;\n}();\n\nconst int dx[] = {-1, 1, 0, 0};\nconst int dy[] = {0, 0, -
```\nstatic bool fast = []()\n{\n    std::cin.tie(0)->sync_with_stdio(false);\n    return true;\n}();\n\nconst int dx[] = {-1, 1, 0, 0};\nconst int dy[] = {0, 0, -1, 1};\n\nint zeroOneBFS(const vector<vector<int>>& matrix)\n{\n    int m = matrix.size();\n    int n = matrix[0].size();\n\n    if (m == 0 || n == 0) return -1;\n\n    vector<vector<int>> dist(m, vector<int>(n, numeric_limits<int>::max()));\n    dist[0][0] = matrix[0][0]; \n\n    deque<pair<int, int>> dq;\n    dq.push_front({0, 0});\n\n    while (!dq.empty())\n    {\n        std::pair<int, int> cur = dq.front();\n        dq.pop_front();\n        int x = cur.first;\n        int y = cur.second;\n\n        for (int i = 0; i < 4; ++i)\n        {\n            int nx = x + dx[i];\n            int ny = y + dy[i];\n\n            if (nx >= 0 && nx < m && ny >= 0 && ny < n)\n            {\n                int new_cost = dist[x][y] + matrix[nx][ny];\n\n                if (new_cost < dist[nx][ny])\n                {\n                    dist[nx][ny] = new_cost;\n\n                    if (matrix[nx][ny] == 0)\n                    {\n                        dq.push_front({nx, ny});\n                    }\n                    else\n                    {\n                        dq.push_back({nx, ny});\n                    }\n                }\n            }\n        }\n    }\n\n    return dist[m - 1][n - 1];\n}\n\nclass Solution\n{\npublic:\n    bool findSafeWalk(vector<vector<int>>& grid, int health)\n    {\n        return zeroOneBFS(grid) < health;\n    }\n};\n```
['C++']