Mai intai trebuie sa te autentifici.
Cod sursa(job #789901)
| Utilizator | Data | 19 septembrie 2012 19:06:31 | |
|---|---|---|---|
| Problema | Floyd-Warshall/Roy-Floyd | Scor | 50 |
| Compilator | fpc | Status | done |
| Runda | Arhiva educationala | Marime | 0.71 kb |
Program Floyd_Warshall;
type matrice= array[1..101,1..101] of word;
Var cost,dist:matrice;
k,n,i,j:byte;
f:text;
Procedure init;
Begin
for i:=1 to n do
for j:=1 to n do dist[i,j]:=cost[i,j];
end;
Procedure floyd(Var dist:matrice);
Begin
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if (dist[i,k]+dist[k,j]<dist[i,j]) then dist[i,j]:=dist[i,k]+dist[k,j];
end;
Begin
assign(f,'royfloyd.in'); reset(f); readln(f,n);
for i:=1 to n do
begin
for j:=1 to n do read(f,cost[i,j]);
readln(f);
end;
init; floyd(dist); close(f); assign(f,'royfloyd.out'); rewrite(f);
for i:=1 to n do
begin
for j:=1 to n do write(f,dist[i,j],' ');
writeln(f);
end;
close(f);
end.
