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

Автор tasyrkin, 10 лет назад, По-английски

Hello everybody!

Recently I have faced the following graph problem: Given a directed graph with nonnegative weights. There is a need to find a number of paths between two nodes which path's weights are less then specified number. Graph may contain cycles and path may contain cycles.

I have found the Yen's algorithm which can find K shortest paths and which may be adjusted to partially solve my problem (the algorithm finds loopless paths) and wondering now if there is an approach to solve the problem.

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

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

You can use simple DP where r[v][k] = number of paths from v to end with weight <= k

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

    Well, that's only if the weights are small numbers? In general with weights like 10^9 this DP will be horrible.

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

      It looks like author have forgotten to specify limits so it is not clear whether simple DP or simple DFS or something else was intended to be used...

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

        There is no limits for a problem, but they may be set as soon as identified. How would you solve such problem with DFS?

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

Please give a link to the problem.

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

In fact, your problem is NP-hard, because it's possible to reduce the longest path problem to it in polynomial time.