Pagini recente » Cod sursa (job #926488) | Cod sursa (job #1533639) | Cod sursa (job #2399481) | Cod sursa (job #2698238) | Cod sursa (job #539036)
Cod sursa(job #539036)
uses crt;
type kl=array[0..15000,0..15000] of integer;
op=array[0..15000] of integer;
var
x:kl;
j2,d,v:op;
f,g:text;
a,b,c,d2,m,n,i,j,c2,min,p,l:longint;
begin
assign(f,'dijkstra.in');
reset(f);
assign(g,'dijkstra.out');
rewrite(g);
readln(f,m,n);
for i:=1 to n do
begin
read(f,a,b,c2);
x[a,b]:=c2;
x[b,a]:=c2;
end;
for i:=1 to n do
for j:=1 to n do
if (x[i,j]=0)and(i<>j)then begin x[j,i]:=10000; x[i,j]:=10000;end;
j2[c]:=1;
for i:=1 to m do
begin
if i<>1 then o[i]:=1;
d[i]:=x[1,i];
end;
for i:=1 to m-1 do
begin
min:=10000; p:=0;
for j:=1 to m do
if (d[j]<min)and(j2[j]<>1)
then begin min:=d[j];p:=j;end;
j2[p]:=1;
for j:=1 to m do
if (x[p,j]+d[p]<d[j] ) then begin d[j]:=x[p,j]+d[p];end;
end;
for i:=2 to m do
write(g,d[i],' ');
close(f);
close(g);
end.