Pagini recente » Cod sursa (job #2926818) | Cod sursa (job #2100464) | Cod sursa (job #2393080) | Cod sursa (job #1987580) | Cod sursa (job #1909066)
var t:array[1..50000]of longint;
a:array[1..30000,1..30000]of integer;
n,m,i,j,x,y,k:word;
ok:boolean;
min:longint;
c:array[1..50000]of longint;
b:array[1..50000]of byte;
begin
assign(input,'dijkstra.in');
reset(input);
readln(n,m);
for i:=1 to n do
for j:=1 to n do
a[i,j]:=maxint;
for i:=1 to m do
begin
readln(x,y,k);
a[x,y]:=k;
end;
close(input);
for i:=1 to n do
begin
c[i]:=a[1,i];
t[i]:=1;
b[i]:=0;
end;
t[1]:=0;
b[1]:=1;
min:=maxlongint;
ok:=true;
while ok do
begin
min:=maxlongint;
for i:=1 to n do
if (b[i]=0)and(c[i]<min) then begin min:=c[i];k:=i;end;
if min<>maxlongint then
begin
b[k]:=1;
for i:=1 to n do
if (b[i]=0)and(c[i]>c[k]+a[k,i]) then
begin
c[i]:=c[k]+a[k,i];
t[i]:=k;
end;
end
else ok:=false;
end;
assign(output,'dijkstra.out');
rewrite(output);
write(c[2]);
for i:=3 to n do write(' ',c[i]);
close(output)
end.