Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

Bellman Ford's algorithm

Revision en1, by Reference, 2016-02-19 20:48:03

in bellman ford algorithm when i relax an edge(u,v) but the distance in u and v is infinite dist[u] = dist[v] = oo and the weight of edge is big negative so what will happen is: dist[u]+w < dist[v] so dist[v] will modified i want to asked if there is necessity to write a condition before the relaxing to avoid that or not and why if not ? because i try some graphs with an arbitary order to edges it gives wrong answer without the condition. thank you all.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Reference 2016-02-19 20:48:03 490 Initial revision (published)