Cod sursa(job #599397)

Utilizator Luncasu_VictorVictor Luncasu Luncasu_Victor Data 28 iunie 2011 17:28:27
Problema Floyd-Warshall/Roy-Floyd Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 1.19 kb
const   fin = 'royfloyd.in'; fout = 'royfloyd.out'; inf = 100 * 100 * 1000 + 1;

type
        matrice = array[1..100,1..100] of longword;
var
        cost : matrice;
        n : word;

procedure init( a, b : longword );
var
        i ,j : word;
begin
        for i := 1 to n do
        for j := 1 to n do
        if (cost[i][j] = a) then cost[i][j] := b;

        if (b = 0) then
        for i := 1 to n do cost[i][i] := 0;
end;

procedure royfloyd();
var
        k ,i ,j : word;
begin
        for k := 1 to n do
        for i := 1 to n do
        for j := 1 to n do
        if (cost[i][k] + cost[k][j] < cost[i][j]) then
        cost[i][j] := cost[i][k] + cost[k][j];
end;

procedure main();
var
        i ,j : word;
begin
        assign( input, fin ); reset( input );
        assign( output, fout ); rewrite( output );

        readln( n );
        for i := 1 to n do
        for j := 1 to n do read( cost[i][j] );

        init( 0, inf );

        royfloyd();

        init( inf, 0 );

        for i := 1 to n do
        begin
                for j := 1 to n do write( cost[i][j], #32 );
                write( #10 );
        end;
end;

begin
        main();
end.