How to determine if two nodes are connected?

前端 未结 11 1177
清酒与你
清酒与你 2020-12-09 03:31

I\'m concerned that this might be working on an NP-Complete problem. I\'m hoping someone can give me an answer as to whether it is or not. And I\'m looking for more of an an

11条回答
  •  臣服心动
    2020-12-09 04:25

    To me it seems like you are on to a solution, but it's possible I misunderstood the problem. If you do like you say, and give the closed edges 1 as weight, you can just apply Dijkstra's algorithm, http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm. This should solve your problem in O(E*lg(V))

提交回复
热议问题