Skip to content

Instantly share code, notes, and snippets.

View csessh's full-sized avatar
👀

Thang Do csessh

👀
View GitHub Profile
@csessh
csessh / dijkstra.py
Last active January 3, 2025 04:41 — forked from kachayev/dijkstra.py
Dijkstra shortest path algorithm based on python heapq heap implementation
from collections import defaultdict
from heapq import heappush, heappop
def dijkstra(edges, start, end) -> Tuple[int, List[str]]:
graph = defaultdict(list)
for src, dest, weight in edges:
graph[src].append((weight, dest))
pq = [(0, start, [])]
seen = set()