Python: How to find if a path exists between 2 nodes in a graph?

后端 未结 5 2253
野性不改
野性不改 2021-01-01 17:55

I am using networkx package of Python.

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-01 18:06

    Use

    shortest_path(G, source, target)
    

    or one of the Shortest Path methods. Stay clear of the methods which return paths between all nodes however if you merely have two specific nodes to test for connectivity.

提交回复
热议问题