The Floyd-Warshall algorithm for shortest paths

Enter the adjacency list of your graph. Each line must start with a vertex label. The other tokens in the line for a vertex u describe the adjacency list of u. They must come in pairs v w, where (u,v) is an edge and w is its weight. Separate all tokens with space(s).

In the example below, the vertex 1 is adjacent with vertices 2, 3, and 5, and the edge weights of (1,2), (1,3), and (1,5) are 3, 8, and -4, respectively.

The maximum input length is limited by 300 characters including spaces.

Program output

Source code