Pagini recente » Istoria paginii utilizator/nenu2008 | Istoria paginii utilizator/mxrcurie | Monitorul de evaluare | Cod sursa (job #859097) | Cod sursa (job #671176)
Cod sursa(job #671176)
program kk;
type ref=^inr;
inr=record
nr:longint;
cost:longint;
adr:ref;
end;
var f:text;
lista,u:array[1..50000] of ref;
q:ref;
lung,h,nod,pos:array[1..50000] of longint;
viz:array[1..50000] of 0..1;
ies:boolean;
n,m,i,a,b,c,nc,xx,nrviz,d,nrheap,key,key1,t:longint;
procedure adaug_in_lista(x,y,z:longint);
begin
new(q);
q^.nr:=y;
q^.adr:=nil;
q^.cost:=z;
if lista[x]=nil then begin
lista[x]:=q;
u[x]:=q;
end
else begin
u[x]^.adr:=q;
u[x]:=q;
end;
end;
procedure sterge_din_heap;
begin
end;
procedure modific_heap(k,val:longint);
begin
h[pos[k]]:=val;
end;
procedure adaug_in_heap(k,val:longint);
begin
end;
procedure dj;
begin
nrviz:=1;
nc:=1;
viz[1]:=1;
nrheap:=0;
repeat
q:=lista[nc];
while q<>nil do
begin
xx:=lung[nc]+q^.cost;
if xx<lung[q^.nr] then begin
if viz[q^.nr]=0 then
if pos[q^.nr]>0 then modific_heap(q^.nr,xx)
else adaug_in_heap(q^.nr,xx);
lung[q^.nr]:=xx;
end;
q:=q^.adr;
end;
nc:=nod[1];
pos[nod[1]]:=0;
viz[nc]:=1;
sterge_din_heap;
nrviz:=nrviz+1;
until nrviz=n;
end;
begin
assign(f,'dijkstra.in');
reset(f);
readln(f,n,m);
for i:=1 to m do
begin
readln(f,a,b,c);
adaug_in_lista(a,b,c);
end;
lung[1]:=0;
for i:=2 to n do lung[i]:=2140000000;
dj;
close(f);
assign(f,'dijkstra.out');
rewrite(f);
for i:=2 to n do
if lung[i]<2140000000 then write(f,lung[i],' ')
else write(f,0,' ');
close(f);
end.