Pagini recente » Cod sursa (job #56188) | Cod sursa (job #475458) | Cod sursa (job #3169822) | Cod sursa (job #645185) | Cod sursa (job #1100953)
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
read(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
d[g[i].y]:=d[g[i].x]+g[i].cost;
ok:=false;
end;
until ok;
for i:=2 to n do
if d[i]=inf then write(h,'0 ')
else write(h,d[i],' ');
close(h);
end.