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

Автор DarkSilver, история, 3 недели назад, По-английски

Given a directed graph, source node and destination node you have to start from source with value 1 and reach destination node along some path where each edge has a multiple associated with it. Find the maximum value you can attain? Assume, if cycles exists it does not increases value to greater than 1.

Can we use Dijkstra's algorithm here or a quadratic dp+dfs is more appropriate?

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

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

Dijkstra won't work for this problem.

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

Auto comment: topic has been updated by DarkSilver (previous revision, new revision, compare).

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

multiple of what, exactly?

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

    So each edge has a value associated and if you travel through that edge the “multiple” is multiplied to get the new value.

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

      Okay. So you're saying that we start with value = 1 at the source destination and every time we go through that edge, value = value * multiplier of edge. We need to get to destination with as big a value as possible. And what is that about the cycles even? Like, you're not allowed to go through a cycle?

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

        You could go through cycles but let's assume the value is always less than 1 when you traverse a cycle ensuring that you do not run into infinite loops.

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

Write it a little better please. Multiple of what exactly? Can you give the original problem statement maybe?

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

Taking the logarithm of each value will make your problem identical to the single source longest path problem. Following the analysis of such a problem, a Dijkstra's algorithm works if and only if your original graph doesn't contain edges with a value (or multiple as you stated it) more than 1, which would correspond to a positive weight on the transformed graph.

I don't get your 'quadratic dp+dfs' though, for it seems that it only works on DAGs. On more general graphs one might suggest using Bellman-Ford to solve this problem.