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

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

I just thought about something.

If I want to find shortest path between A and B with negative edges, but no negative cycle.

How about we start Dijkstra with source A and then with source B and return the minimum of the two results.

I was thinking and I cannot find a counter-example.

Any ideas?

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

»
14 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится +1 Проголосовать: не нравится

counter-example:
1 2 5
1 3 2
2 3 -7
3 4 -5
3 5 1
4 5 2
Path from 1 to 5.

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

Of course, your idea is wrong:

A-C: 100
A-D: 120
C-D: -30
B-C: 100
B-E: 120
C-E: -30

Path from A to B. (ans is 190 in both cases)

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

Search "dijkstra with potentials" or "ford-bellman".