graph = defaultdict(list). start = connections[0][0] # Add all nodes because it's biderctional. for src, dst, wt in connections this is not minimum spanning Tree my friend. this is Dijkstra's shortest path.1 1 Definition : Given an undirected graph G = (V, E), a spanning tree of G is any subgraph of G that is a tree Minimum Spanning Trees (Ch. 23) Commercial grade solar powered security lights