Skip to content

Commit 99d1308

Browse files
Reject blocked endpoints in binary-grid Dijkstra
1 parent 6e03a48 commit 99d1308

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎graphs/dijkstra_binary_grid.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ def dijkstra(
4444
(4.0, [(0, 0), (0, 1), (0, 2), (1, 2), (2, 2)])
4545
"""
4646
rows, cols = grid.shape
47+
if grid[source] != 1 or grid[destination] != 1:
48+
return np.inf, []
49+
4750
dx = [-1, 1, 0, 0]
4851
dy = [0, 0, -1, 1]
4952
if allow_diagonal:

0 commit comments

Comments
 (0)