Floyd–Warshall Algorithm
Learn Floyd–Warshall Algorithm
Introduction
We are given a directed or undirected weighted graph with vertices. We need to find the shortest distance between every pair of vertices and .
The graph may contain edges with negative weights, but it must not contain any negative-weight cycle.
This algorithm can also be used to detect negative cycles: if after the algorithm finishes we get