from heapq import heappush, heappop, heapify
def load_graph():
with open('dijkstra.txt') as f:
lines = f.readlines()
head_set = []
length_set = []
for line in lines:
edges = line.split()[1:]
heads = []
lengths = []
for edge in edges:
head, length = list(map(int, edge.split(',')))
heads.append(head - 1)
lengths.append(length)
head_set.append(heads)
length_set.append(lengths)
return head_set, length_set
head_set, length_set = load_graph()
# tuples in (cost, head)
heap = [(0, 0)]
S = set()
Q = set([i for i in range(0, 200)])
d = [1000000 for i in range(0, 200)]
d[0] = 0
while len(Q) > 0:
length, u = heappop(heap)
if(u not in Q): continue
Q.remove(u)
S.add(u)
for i, v in enumerate(head_set[u]):
if v not in S:
if d[v] > d[u]+ length_set[u][i]:
d[v] = d[u] + length_set[u][i]
heappush(heap, (d[v], v))
tmp = []
for i in [7,37,59,82,99,115,133,165,188,197]:
tmp.append(d[i-1])
print(tmp)