Skip to content

Commit 017b770

Browse files
authored
Update leetcode_0787_cheapest_flights_within_k_stops_medium.py
1 parent 801a95b commit 017b770

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

python/bfs_heap_topological_sort/heap/leetcode_0787_cheapest_flights_within_k_stops_medium.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ def findCheapestPrice(self, n: int, flights: List[List[int]], src: int, dst: int
6363
weight, stop, city = heapq.heappop(queue)
6464
if city == dst:
6565
return weight
66+
if (city, stop) in dequeued: continue
6667
dequeued.add((city, stop))
6768
if stop < K + 1: # stop <= K
6869
for n_dst, n_weight in graph[city]:
69-
if (n_dst, stop) in dequeued:
70+
if (n_dst, stop+1) in dequeued:
7071
continue
7172
heapq.heappush(queue, (weight+n_weight, stop+1, n_dst))
7273
return -1

0 commit comments

Comments
 (0)