Pagini recente » Cod sursa (job #1461348) | Cod sursa (job #2328318) | Istoria paginii runda/12/clasament | Cod sursa (job #547982) | Cod sursa (job #135047)
Cod sursa(job #135047)
var id,cs,ct,viz,x,s,q:array[0..200010] of longint;
a,b,i,j,n,m,u,t,pe: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(s[i],q[i],viz[i]);
inc(id[s[i]]);
inc(id[q[i]]);
end;
for i:=1 to n do
id[i]:=id[i]+id[i-1];
for i:=1 to m do
begin
inc(ct[s[i]]);
inc(ct[q[i]]);
x[id[s[i]-1]+ct[s[i]]]:=q[i];
x[id[q[i]-1]+ct[q[i]]]:=s[i];
cs[id[s[i]-1]+ct[s[i]]]:=viz[i];
cs[id[q[i]-1]+ct[q[i]]]:=viz[i];
end;
fillchar(ct,sizeof(ct),0);
fillchar(viz,sizeof(viz),0);
s[1]:=a;
pe:=1;u:=1;
while pe<=u do
begin
for i:=id[s[pe]-1]+1 to id[s[pe]] do
begin
if viz[x[i]]=0 then
begin
inc(u);
s[u]:=x[i];
viz[x[i]]:=1;
if x[i]<s[pe] then
ct[x[i]]:=ct[s[pe]]-cs[i]
else
ct[x[i]]:=ct[s[pe]]+cs[i];
if x[i]=b then
begin
writeln(ct[x[i]]);
close(output);
halt;
end;
end;
end;
inc(pe);
end;
close(input);close(output);
end.