floyd-warshall algorithm
an algorithm to find the distance matrix of a directed weighted graph

let
be a weighted graph with the set of vertices
- we denote by
the induced subgraph by the vertices
- for every pair of vertices
we denote by
the induced subgraph by the vertices
- for every pair of vertices,
we denote by
one of the minimal paths (if it exists) from
to
in
for every pair of vertices
- if in
there exists a minimal path from
to
,
, we write
- if in \(G^{(k)}_{ij}\) there exists a path from \(i\) to \(j\) that contains a negative cycle we write \(d^{(k)}_{ij} = -\infty\)
- if in \(G^{(k)}_{ij}\) there isnt a path from \(i\) to \(j\) we write \(d^{(k)}_{ij} = \infty\)
- for every
if in
there isnt a negative cycle that touches
then
- for every
if in
there is a negative cycle that touches
then
- for every
,
(if it exists) is the shortest path from
to
without any vertices in between, meaning the path is just the edge
- for every
,
(if it exists) is the shortest path from
to
, i.e.
-
and
, otherwise
- if the directed edges
are defined in
, then
the time complexity of the algorithm is 