"""

class Solution {

public:

```
void dfs(vector<vector<int>>& rooms, int i, int j, int m, int n, int dist){
if(i <0 || i>=m || j<0 || j>= n || rooms[i][j] == -1 || dist > rooms[i][j])
return;
rooms[i][j] = dist;
dfs(rooms, i+1, j, m, n, dist+1);
dfs(rooms, i-1, j, m, n, dist+1);
dfs(rooms, i, j+1, m, n, dist+1);
dfs(rooms, i, j-1, m, n, dist+1);
}
void wallsAndGates(vector<vector<int>>& rooms) {
int m = rooms.size();
if (m < 1) return;
int n = rooms[0].size();
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
int dist = 0;
if(rooms[i][j] == 0)
dfs(rooms, i, j, m, n, dist);
}
}
}
```

};

"""