AlgoFrames

Matrix after k = 1

Warm-up · Trace the algorithm · about 5 min

The vertices are numbered 1 to 4. Floyd-Warshall first allows vertex 1 as a midpoint. Predict how the matrix changes in that round.

Example 1

Input:

{"edges":[[1,2,2],[1,3,6],[2,3,3],[3,4,1],[4,1,4],[2,4,7]]}

Output:

[[0,2,6,"∞"],["∞",0,3,7],["∞","∞",0,1],[4,6,10,0]]

Edges are one-way. Row = from, column = to.

Constraints

  • Rows and columns are scanned in order 1 to 4.
  • Edges are one-way.

Learn the idea first: Floyd-Warshall: all pairs, a visual lesson.

More Floyd-Warshall: all pairs problems