Pagini recente » Cod sursa (job #596182) | Cod sursa (job #2270590) | Cod sursa (job #660300) | Cod sursa (job #2577833) | Cod sursa (job #342229)
Cod sursa(job #342229)
type ref=^nod;
nod=record
nr:longint;
adr:ref;
end;
var a:array[1..100,1..100] of longint;
s:array[1..100] of 0..1;
v,sf,u2,cost,cost2:ref;
n,m,x,y,i,j,k,c:longint;
f,g:text;
ok:boolean;
begin
assign(f,'sate.in');
assign(g,'sate.out');
reset(f);rewrite(g);
readln(f,n,m,x,y);
for i:=1 to n do
for j:=1 to n do
if i<>j then
a[i,j]:=-1;
for i:=1 to m do
begin
readln(f,j,k,c);
a[j,k]:=c;
a[k,j]:=c;
end;
new(v);
v^.nr:=x;
v^.adr:=nil;
s[x]:=1;
sf:=v;
new(cost);
cost^.nr:=0;
cost^.adr:=nil;
cost2:=cost;
repeat
for i:=1 to n do
if (a[v^.nr,i]>0) and (s[i]=0) then
begin
s[i]:=1;
new(u2);
u2^.nr:=i;
u2^.adr:=nil;
sf^.adr:=u2;
sf:=u2;
new(u2);
if v^.nr<i then
u2^.nr:=cost^.nr+a[v^.nr,i]
else
u2^.nr:=cost^.nr-a[v^.nr,i];
u2^.adr:=nil;
cost2^.adr:=u2;
cost2:=u2;
if i=y then
begin
ok:=true;
break;
end;
end;
if ok=false then
begin
u2:=v^.adr;
dispose(v);
v:=u2;
u2:=cost^.adr;
dispose(cost);
cost:=u2;
end;
until ok=true;
write(g,cost2^.nr);
close(f);close(g);
end.