DarkSilver's blog

By DarkSilver, history, 3 weeks ago, In English

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?

  • Vote: I like it
  • +10
  • Vote: I do not like it

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Dijkstra won't work for this problem.

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
3 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

multiple of what, exactly?

  • »
    »
    3 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

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

    • »
      »
      »
      3 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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

»
3 weeks ago, # |
  Vote: I like it +9 Vote: I do not like it

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.