Skip to content

Instantly share code, notes, and snippets.

@zuzhaoye
zuzhaoye / dijkstra.py
Created December 7, 2019 03:56 — forked from dingran/dijkstra.py
Python implementation of Dijkstra's algorithm, single source all desinations and single source single destination
from collections import defaultdict
def build_graph(edge_list):
graph = defaultdict(list)
seen_edges = defaultdict(int)
for src, dst, weight in edge_list:
seen_edges[(src, dst, weight)] += 1
if seen_edges[(src, dst, weight)] > 1: # checking for duplicated edge entries
continue