22 lines
567 B
Plaintext
22 lines
567 B
Plaintext
const V=4;
|
|
dist:=V.pump(List,V.pump(List,Void.copy).copy); // VxV matrix of Void
|
|
foreach i in (V){ dist[i][i] = 0 } // zero vertexes
|
|
|
|
/* Graph from the Wikipedia:
|
|
1 2 3 4
|
|
d ----------
|
|
1| 0 X -2 X
|
|
2| 4 0 3 X
|
|
3| X X 0 2
|
|
4| X -1 X 0
|
|
*/
|
|
dist[0][2]=-2; dist[1][0]=4; dist[1][2]=3; dist[2][3]=2; dist[3][1]=-1;
|
|
|
|
dist,next:=FloydWarshallWithPathReconstruction(dist);
|
|
println("Shortest distance array:"); printM(dist);
|
|
println("\nPath array:"); printM(next);
|
|
println("\nAll paths:");
|
|
foreach u,v in (V,V){
|
|
if(p:=path(next,u,v)) p.println();
|
|
}
|