solving.py 文件源码

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

项目:graffunc 作者: Aluriak 项目源码 文件源码
def shortest_path(graph, source, target):
    """Return the windowed shortest path between source and target
    in the given graph.

    Graph is expected to be a dict {node: {successors}}.

    Return value is a tuple of 2-tuple, each 2-tuple representing a
    window of size 2 on the path.

    """
    if source == target: return tuple()  # no move needed
    nxg = nx.Graph()
    for node, succs in graph.items():
        for succ in succs:
            nxg.add_edge(node, succ)
    return tuple(nx.dijkstra_path(nxg, source, target))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号