kruskals_quick_union.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:Visualization-of-popular-algorithms-in-Python 作者: MUSoC 项目源码 文件源码
def CreateGraph():
    G = nx.Graph()
    f = open('input.txt')
    n = int(f.readline())
    wtMatrix = []
    for i in range(n):
        list1 = map(int, (f.readline()).split())
        wtMatrix.append(list1)
    # Adds egdes along with their weights to the graph 
    for i in range(n) :
        for j in range(n)[i:] :
            if wtMatrix[i][j] > 0 :
                    G.add_edge(i, j, length = wtMatrix[i][j]) 
    return G



# draws the graph and displays the weights on the edges
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号