Cod sursa(job #433993)

Utilizator valytgjiu91stancu vlad valytgjiu91 Data 4 aprilie 2010 21:22:43
Problema Algoritmul lui Dijkstra Scor 10
Compilator fpc Status done
Runda Arhiva educationala Marime 0.72 kb
const nmax=50002;
const mmax=250002;
const inf=2000000000;
type muchie=record
        x,y,cost:longint;
        end;
var g:array[1..mmax]of muchie;
d:array[1..nmax]of longint;
i,x,y,c,m,n:longint;
ok:boolean;
f,h:text;
begin
assign(f,'dijkstra.in');
reset(f);
assign(h,'dijkstra.out');
rewrite(h);
read(f,n,m);
for i:=1 to m do
begin
readln(f,x,y,c);
g[i].x:=x;
g[i].y:=y;
g[i].cost:=c;
if x=1 then d[y]:=c;
end;
for i:=2 to n do
if d[i]=0 then d[i]:=inf;
repeat
ok:=true;
for i:=1 to m do
    if d[g[i].y]>d[g[i].x]+g[i].cost then
           begin
            ok:=false;
            d[g[i].y]:=d[g[i].x]+g[i].cost;
           end;
until ok;
for i:=2 to n do
   write(h,d[i],' ');
close(h);
end.