c++ code using Dijkstra's algorithm (BFS) -- with inline explanation
Complexity
Time complexity: o(mxn), where m is number of rows and n is number of columns

Space complexity: o(mxn), hwere m is number of rows and n is number of

# Complexity
- Time complexity: o(mxn), where m is number of rows and n is number of columns
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: o(mxn), hwere m is number of rows and n is number of columns
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
#define p pair<int,pair<int,int>>
class Solution {
public:
    bool bfs(vector<vector<int>>& grid, int health) {
        //take a priority queue --> max heap
        priority_queue<p, vector<p>> pq;
        //initially the health is maximum starting from row 0,0, check if the value is 1 or 0 at the cell and update current health according to it
        pq.push({grid[0][0] ? health-1 : health,{0,0}});
        //a 2D matrix to mark the grid as visited
        vector<vector<int>> visited(grid.size(), vector<int>(grid[0].size()));
        //mark 0,0 grid as visited
        visited[0][0] = 1;

        int delta_row[] = {-1,0,1,0};
        int delta_col[] = {0,-1,0,1};

        //explore the grid using pq
        while(!pq.empty()) {
            //take the health from pq
            int current_health = pq.top().first;
            //take row
            int row = pq.top().second.first;
            //take column
            int col = pq.top().second.second;
            //pop the queue
            pq.pop();
            //check if we have reached the last row and column
            if(row == grid.size()-1 and col == grid[0].size()-1) {
                //check if there's health remaining
                if(current_health >= 1) return true;
            }
            //explore top, bottom left and right adjacent cells
            for(int i=0; i<4; i++) {
                //take neighbour row
                int neigh_row = row + delta_row[i];
                //take neighbour column
                int neigh_col = col + delta_col[i];
                //check boundaries, also if the neighbour cell is not a visited one
                if(neigh_row >= 0 and neigh_row < grid.size() and neigh_col >= 0 and neigh_col < grid[0].size() and !visited[neigh_row][neigh_col]){
                    //mark the cell as visited
                    visited[neigh_row][neigh_col] = 1;
                    //push the neigh row and column to the pq, check if the value is 1 or 0 at the cell and update current health according to it
                    pq.push({grid[neigh_row][neigh_col] ? current_health-1 : current_health, {neigh_row, neigh_col}});
                }
            }
        }
        //if the last row is not reached
        return false;
    }
    bool findSafeWalk(vector<vector<int>>& grid, int health) {
        return bfs(grid, health);
    }
};
```
['Breadth-First Search', 'Shortest Path', 'C++']