Блог пользователя Domonion

Автор Domonion, история, 8 лет назад, По-русски

Собственно, задача такова:

Дан неориентированный взвешенный граф. Для каждой вершины найдите длину кратчайшего простого цикла, проходящего через данную вершину.

Быстрейшее решение, что у меня есть, работает за N^4

  • Проголосовать: нравится
  • +12
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been translated by Domonion (original revision, translated revision, compare)

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

are there negative edges?

»
8 лет назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

Решение за O(N3).

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

If O(n^3logn) is good enough, for each node, for each edge of the node, remove the edge, run dijkstras to find the distance from the node to the neighbor on the other side of the edge, and add the edge weight to it. The answer is the minimum of these.

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I think it's possible to do in . To compute answer for vertex v, run Dijkstra from it then for every edge w suposse that this edge is included in some cycle of v in the way (where wA and wB are vertexes connected by edge w) and calculate its weight. Answer for v gonna be a minimum of these weights.

  • »
    »
    8 лет назад, # ^ |
      Проголосовать: нравится -8 Проголосовать: не нравится

    It's also O(n^3 log n)

    • »
      »
      »
      8 лет назад, # ^ |
        Проголосовать: нравится -10 Проголосовать: не нравится

      No it's not. For each vertex you run dijkstra and check all edges so actually it is O(n * (m + mlogn)). Of course if there will be like n2 edges then it indeed gonna work in O(n3 * logn), but if such constraints exists then n should be quite small.

      • »
        »
        »
        »
        8 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится +13 Проголосовать: не нравится

        Your algorithm does not always compute simple cycles. Consider the cycle , which is not a simple cycle, but is taken into account by your algorithm.

»
8 лет назад, # |
Rev. 2   Проголосовать: нравится +11 Проголосовать: не нравится

please ignore this :(

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

I don't know if this is a coincidence or not, but it seems you are not the only one solving this problem: http://research.haifa.ac.il/~raphy/papers/all-cycles.pdf