diff --git a/graphs/dijkstra.py b/graphs/dijkstra.py index 6b08b28fc..4b6bc347b 100644 --- a/graphs/dijkstra.py +++ b/graphs/dijkstra.py @@ -20,12 +20,12 @@ import heapq def dijkstra(graph, start, end): heap = [(0, start)] # cost from start node,end node - visited = [] + visited = set() while heap: (cost, u) = heapq.heappop(heap) if u in visited: continue - visited.append(u) + visited.add(u) if u == end: return cost for v, c in G[u]: