Pagini recente » Cod sursa (job #596364) | Cod sursa (job #1946366) | Cod sursa (job #2571091) | Cod sursa (job #3281421) | Cod sursa (job #387687)
Cod sursa(job #387687)
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;
vx,vy:word;
vcost:longint;
ok:boolean;
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
begin
readln(vx,vy,vcost);
with g[i] do
begin
x:=vx;
y:=vy;
cost:=vcost;
end;
if vx=1 then c[vy]:=vcost;
end;
repeat
ok:=true;
for i:=1 to m do
begin
vy:=g[i].y;
vcost:=c[g[i].x]+g[i].cost;
if c[vy]>vcost then
begin
c[vy]:=vcost;
ok:=false;
end;
end;
until ok;
for i:=2 to n do
if c[i]=mymax then write('0 ')
else write(c[i],' ');
close(output);
close(input);
end.