graph_test.py 文件源码

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

项目:algorithm 作者: Firkraag 项目源码 文件源码
def testBellmanFord(self):
        s = Vertex('s')
        t = Vertex('t')
        y = Vertex('y')
        x = Vertex('x')
        z = Vertex('z')
        vertices = [s, t, y, x, z]
        edges = [(s, t), (s, y), (t, y), (t, x), (t, z), (y, x), (y, z), (x, t), (z, s), (z, x)]
        weight = [6, 7, 8, 5, -4, -3, 9, -2, 2, 7]
        G = Graph(vertices, edges)
        we = dict()
        for x,y in zip(edges, weight):
            we[x] = y    
        def w(x, y):
            return we[(x, y)]        
        G.Bellman_Ford(w, z)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号