Dijkstra for longest path in a DAG

后端 未结 6 1999
面向向阳花
面向向阳花 2020-12-01 14:55

I am trying to find out if it is possible to use Dijkstra\'s algorithm to find the longest path in a directed acyclic path. I know that it is not possible to find the longes

6条回答
  •  醉梦人生
    2020-12-01 15:22

    Not enough reputation to comment on @punkyduck's answer, but I'd like to mention that replacing min with max in the DAG

    a ——2——→ b ——2——→ c
    │                 ↑
    │                 │
    1                 4
    │                 │
    └——————→ d ———————┘
    

    actually works, as the algorithm will

    • first examine aab=2, ad=1l(b)=(ab,2), l(d)=(ad,1)
    • then examine b since we use maxabc=2l(c)=(abc,2)
    • then examine c since abc>adNothing happens
    • at last examine dadc=5 ⇨ update l(c)=(adc,5)

    So at the last step the correct longest path adc is found. Just to point out the mistake.

提交回复
热议问题