cost inf=1000000; var l:array[1..20,1..20] of longint; n,v,vs,i,j:byte; d:array[1..20]of longint; p:array[1..20]of byte; s:array[1..

20]of boolean; min:longint; procedure citire; var f:text; m,i,j,x,y:byte; z:longint; begin assign(f,’graf.txt’); reset(f); read(f,n,m,vs); for i:=1 to n do for j:=1 to n do l[i,j]:=inf; for i:=1 to m do begin read(f,x,y,z); l[x,y]:=z; end; end; procedure drum(v:byte); begin if v<>vs then drum(p[v]); write(v,’ ’); end; begin clrscr; citire; for i:=1 to n do begin d[i]:=l[vs,i]; if d[i]<> inf then p[i]:=vs; s[i]:=false; end; s[vs]:=true; for i:=1 to n-2 do min:=inf+1; for j:=1 to n do if not s[j] and (d[j]<min)then begin min:=d[j]; v:=j; end; s[v]:=true; for j:=1 to n do if not s[j] and (d[j]>d[v]+l[v,j]) then begin

writeln. p[j]:=v.j]. end.’iar drumul este’).vs‚’la’.’este’. . for i:=1 to n do if i<>vs then if d[i]=inf then writeln(’nu exista drum de la ’‚vs.’la’. drum(i).i.d[j]:= d[j]>d[v]+l[v. end. end. end.d[i].i) else begin write(’lung drumului min de la ’.

Sign up to vote on this title
UsefulNot useful