def CreateGraph():
G = nx.DiGraph()
f = open('input.txt')
n = int(f.readline())
wtMatrix = []
for i in range(n):
list1 = map(int, (f.readline()).split())
wtMatrix.append(list1)
source = int(f.readline()) #source vertex from where BFS has to start
#Adds egdes along with their weights to the graph
for i in range(n):
for j in range(n):
if wtMatrix[i][j] > 0:
G.add_edge(i, j, length = wtMatrix[i][j])
return G, source
#draws the graph and displays the weights on the edges
bfs.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录