Skip to content

Instantly share code, notes, and snippets.

@potpath
potpath / dijkstra.py
Last active March 1, 2023 23:40 — forked from econchick/gist:4666413
Python implementation of Dijkstra's Algorithm using heapq
import heapq
from collections import defaultdict
class Graph:
def __init__(self, n):
self.nodes = set(range(n))
self.edges = defaultdict(list)
self.distances = {}