“””Scientific Computation Project 2
Your CID here:
“””
def func1(G,x):
“””
Code for Part 1, question 1(a)
Input:
G: A weighted NetworkX graph
x: an integer
Output:
Fdict: A dictionary
“””
import networkx as nx
import heapq
Fdict = {}
Mdict = {}
Mlist = []
heapq.heappush(Mlist,[0,x])
Mdict[x]=Mlist[0]
while len(Mlist)>0:
dpop,npop = heapq.heappop(Mlist)
if npop != -1000:
del Mdict[npop]
Fdict[npop] = dpop
for a,b,c in G.edges(npop,data=’weight’):
if b in Fdict:
pass
elif b in Mdict:
dcomp = dpop + c
if dcomp