Grid Search
One of the really annoying things with grid search is that for all the directions, I need to code the case.
vector<int> DIR = {0, 1, 0, -1, 0};
...
for (int i = 0; i < 4; ++i) {
int nr = r + DIR[i], nc = c + DIR[i+1];
if (nr < 0 || nr == m || nc < 0 || nc == n || mat[nr][nc] != -1) continue;
mat[nr][nc] = mat[r][c] + 1;
q.emplace(nr, nc);
}
I have a better way for this?? Yes
vector<vector<int>> edges = {{0,1}, {1,0}}