AlgoFrames

Rounds needed

Warm-up · Trace the algorithm · about 5 min

Bellman-Ford runs from node 0 on a chain of 4 nodes. The edges are listed from the far end first. Answer each question before the step plays.

Example 1

Input:

{"edges":[[2,3,1],[1,2,4],[0,1,2]],"source":0}

Output:

[0,2,6,7]

Final distances are 0, 2, 6, 7.

Constraints

  • Edges are checked in the listed order.
  • Edges are one-way.

Learn the idea first: Bellman-Ford and negative edges, a visual lesson.

More Bellman-Ford and negative edges problems