Pagini recente » Cod sursa (job #887464) | Cod sursa (job #2743400) | Cod sursa (job #929621) | Cod sursa (job #391145) | Cod sursa (job #135042)
Cod sursa(job #135042)
var id,id1,cs,ct,viz,x,s:array[0..200010] of longint;
a,b,i,j,n,m,p,u,q,t:longint;
begin
assign(input,'sate.in');reset(input);
assign(output,'sate.out');rewrite(output);
readln(n,m,a,b);
for i:=1 to m do
begin
readln(p,q,t);
inc(id[p]);
inc(id[q]);
end;
for i:=1 to n do
id[i]:=id[i]+id[i-1];
reset(input);
readln(n,m,a,b);
for i:=1 to m do
begin
readln(p,q,t);
inc(ct[p]);
inc(ct[q]);
x[id[p-1]+ct[p]]:=q;
x[id[q-1]+ct[q]]:=p;
cs[id[p-1]+ct[p]]:=t;
cs[id[q-1]+ct[q]]:=t;
end;
fillchar(ct,sizeof(ct),0);
s[1]:=a;
p:=1;u:=1;
while p<=u do
begin
for i:=id[s[p]-1]+1 to id[s[p]] do
begin
if viz[x[i]]=0 then
begin
inc(u);
s[u]:=x[i];
viz[x[i]]:=1;
if x[i]<s[p] then
ct[x[i]]:=ct[s[p]]-cs[i]
else
ct[x[i]]:=ct[s[p]]+cs[i];
if x[i]=b then
begin
writeln(ct[x[i]]);
close(output);
halt;
end;
end;
end;
inc(p);
end;
close(input);close(output);
end.