Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita212efe

Browse files
ziyzhupoyea
authored andcommitted
Corrected wrong Dijkstra priority queue implementation (#909)
* Corrected wrong DFS implementation* changed list into hash set for dijkstra priority queue implementation.
1 parent12a16d6 commita212efe

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

‎graphs/dijkstra.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
defdijkstra(graph,start,end):
2222
heap= [(0,start)]# cost from start node,end node
23-
visited=[]
23+
visited=set()
2424
whileheap:
2525
(cost,u)=heapq.heappop(heap)
2626
ifuinvisited:
2727
continue
28-
visited.append(u)
28+
visited.add(u)
2929
ifu==end:
3030
returncost
3131
forv,cinG[u]:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp