Skip to content

Switching to segtree based Dijkstra for extra speed#55

Draft
bjorn-martinsson wants to merge 1 commit intocheran-senthil:masterfrom
bjorn-martinsson:new_dijkstra
Draft

Switching to segtree based Dijkstra for extra speed#55
bjorn-martinsson wants to merge 1 commit intocheran-senthil:masterfrom
bjorn-martinsson:new_dijkstra

Conversation

@bjorn-martinsson
Copy link
Collaborator

Python has a problem with being slow when it comes to having tuples inside of a heap. There have been multiple problems on codeforces.com with currently no accepted python heap Dijkstra solutions. This PR adds a much more optimized Dijkstra using segment trees to get around using tuples and heaps.

@@ -1,18 +1,50 @@
from heapq import heappop, heappush
inf = -1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think maybe having a comment here would be nice

Comment on lines +36 to +37
def dijkstra(self, graph, start):
n = len(graph)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small docstring would be nice

D = DistanceKeeper(n)
D[start] = 0

for node in Dseg.trav():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dseg -> D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants