program MSTwarshall (input, output); const maxSize = 20; var numVertices, i, j, k: integer; matrix, copy: array[1..maxSize, 1..maxSize] of real; function min (x, y: real): real; begin if x < y then min := x else min := y end; function max (x, y: real): real; begin if x > y then max := x else max := y end; begin writeln('enter #of vertices '); read(numVertices); writeln('enter undirected edges u v weight, eof to terminate'); writeln('edge weights should be unique'); for i := 1 to numVertices do for j := 1 to numVertices do matrix[i, j] := 999999; while not eof do begin read(i, j); read(matrix[i, j]); matrix[j, i] := matrix[i, j] end; writeln('input matrix'); for i := 1 to numVertices do begin for j := 1 to numVertices do begin if matrix[i, j] = 999999 then write(-1.0 : 8 : 2) else write(matrix[i, j] : 8 : 2); copy[i, j] := matrix[i, j] end; writeln end; for k := 1 to numVertices do for i := 1 to numVertices do if matrix[i, k] < 999999 then for j := 1 to numVertices do matrix[i, j] := min(matrix[i, j], max(matrix[i, k], matrix[k, j])); writeln('output matrix'); for i := 1 to numVertices do begin for j := 1 to numVertices do if matrix[i, j] = 999999 then write(-1.0 : 8 : 2) else write(matrix[i, j] : 8 : 2); writeln end; for i := 1 to numVertices do for j := i + 1 to numVertices do if matrix[i, j] = copy[i, j] then writeln(i, j, matrix[i, j] : 8 : 2); end.