Finding shortest circuit in a graph that visits X nodes at least once

后端 未结 1 1236
醉梦人生
醉梦人生 2020-12-19 05:50

Even though I\'m still a beginner, I love solving graph related problems (shortest path, searches, etc). Recently I faced a problem like this :

Given

相关标签:
1条回答
  • 2020-12-19 06:15

    Here is a solution which likely to be fast enough:
    1)Run shortest path search algorithm from every blue node(this can be done in O(X * (E log N))) to compute pairwise distances.
    2)Build a new graph with zero vertex and blue vertices only(X + 1 vertices). Add edges using pairwise distances computed during the first step.
    3)The new graph is small enough to use dynamic programming solution for TSP(it has O(X^2 * 2^X) time complexity).

    0 讨论(0)
提交回复
热议问题