Pagini recente » Cod sursa (job #2027521) | Cod sursa (job #2788992) | Cod sursa (job #1722493) | Cod sursa (job #2158727) | Cod sursa (job #1423429)
var n,m,i,j,k,x,y:longint;
a,b,c:array[1..50000] of longint;
begin
// assign(input,'input.in');
assign(input,'dijkstra.in');
assign(output,'dijkstra.out');
reset(input);
rewrite(output);
read(n,m);
for i:=1 to m do begin
read(x,y,k);
if (c[y]=0) or (c[x]+k<c[y]) then begin
a[y]:=k;
b[y]:=x;
c[y]:=c[x]+k;
end;
end;
b[1]:=0;
for i:=2 to n do begin
j:=i;
k:=0;
while b[j]>0 do begin
k:=k+a[j];
j:=b[j];
end;
write(k,' ');
// write(c[i],' ');
end;
end.