Cod sursa(job #1672825)

Utilizator DoubleNyNinicu Cristian DoubleNy Data 3 aprilie 2016 10:02:16
Problema Floyd-Warshall/Roy-Floyd Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 0.83 kb
program royfloyd; 
var cost:array[1..100,1..100] of integer; 
    k,i,j,n:integer; 

Begin
	 assign(input,'royfloyd.in'); reset(input); 
	 assign(output,'royfloyd.out'); rewrite(output); 
     read(n); 
     writeln(n);
     for i:=1 to n do 
          for j:=1 to n do begin 
                              read(cost[i,j]); 
                              if (i<>j) and (cost[i,j]=0) then cost[i,j]:=maxint;
                            end;
     //Roy-Floyd
     for k:=1 to n do 
         for i:=1 to n do 
             for j:=1 to n do 
             if cost[i,j]>cost[i,k]+cost[k,j] then 
             cost[i,j]:=cost[i,k]+cost[k,j]; 

       for i:=1 to n do 
     begin
            for j:=1 to n do write(cost[i,j],' ');
            writeln; 
     end;  


     
     close(input);
     close(output);      
End.