Pagini recente » Cod sursa (job #43827) | Cod sursa (job #2109781) | Cod sursa (job #3001231) | Cod sursa (job #2377252) | Cod sursa (job #1033402)
type vector=record
i,d:longint;
end;
type sate=record
i,j,d:longint;
end;
var a:array[0..110000] of sate;
b:array[0..110000] of vector;
q:array[0..110000] of longint;
i,n,m,x,y,p,u,k:longint;
f,g:text;
begin
assign(f,'sate.in');reset(f);
assign(g,'sate.out');rewrite(g);
readln(f,n,m,x,y);
for i:=1 to m do
readln(f,a[i].i,a[i].j,a[i].d);
b[0].i:=x;b[0].d:=0;
p:=0;u:=0;
while p<=u do
begin
for i:=1 to m do
begin
if (b[p].i=a[i].i) and (q[a[i].j]=0) then
begin
u:=u+1;
b[u].i:=a[i].j;
if b[u].i>a[i].i then b[u].d:=b[p].d+a[i].d
else b[u].d:=b[p].d-a[i].d;
if b[u].i=y then k:=b[u].d;
end;
if (b[p].i=a[i].j) and (q[a[i].i]=0) then
begin
u:=u+1;
b[u].i:=a[i].i;
if b[u].i>a[i].j then b[u].d:=b[p].d+a[i].d
else b[u].d:=b[p].d-a[i].d;
if b[u].i=y then k:=b[u].d;
end;
end;
q[b[p].i]:=1;
p:=p+1;
if k<>0 then BREAK;
end;
writeln(g,k);
close(f);close(g);
end.