Skip to content

Instantly share code, notes, and snippets.

View whiledoing's full-sized avatar

whiledoing whiledoing

View GitHub Profile
@whiledoing
whiledoing / dijkstra.py
Last active December 28, 2019 11:10 — forked from kachayev/dijkstra.py
[python-dijkstra] Dijkstra shortest path algorithm based on python heapq heap implementation #python #algorithm
from collections import defaultdict
from heapq import *
def dijkstra(edges, f, t):
g = defaultdict(list)
for l,r,c in edges:
g[l].append((c,r))
# dist records the min value of each node in heap.
q, seen, dist = [(0,f,())], set(), {f: 0}