Pagini recente » Cod sursa (job #2317809) | Cod sursa (job #1355413) | Cod sursa (job #1855952) | Cod sursa (job #910259) | Cod sursa (job #386594)
Cod sursa(job #386594)
type muchie=record
x,y,cost:word;
end;
const nmax=50000;
mmax=250000;
mymax=maxlongint div 2;
var n:word;
m,i:longint;
g:array[1..mmax]of muchie;
c:array[1..nmax]of longint;
ok:byte;
begin
assign(input,'dijkstra.in');
reset(input);
assign(output,'dijkstra.out');
rewrite(output);
filldword(c,sizeof(c)div 4,mymax);
c[1]:=0;
readln(n,m);
for i:=1 to m do
with g[i] do
begin
readln(x,y,cost);
if x=1 then c[y]:=cost;
end;
repeat
ok:=0;
for i:=1 to m do
begin
if c[g[i].y]>c[g[i].x]+g[i].cost then
begin
c[g[i].y]:=c[g[i].x]+g[i].cost;
ok:=255;
end;
end;
until ok<128;
for i:=2 to n do
if c[i]=mymax then write('0 ')
else write(c[i],' ');
close(output);
close(input);
end.