dist
with the same dimensions as mat
to store the distances.0
, add its coordinates to the queue and set its distance in dist
to 0
.1
, set its distance in dist
to a large value (indicating that the distance is not yet calculated).dist
is greater than the current cell's distance plus 1, update the adjacent cell's distance and add it to the queue.dist
matrix.