program NishTel;

type TLine=record
        lod, ldo, lag:longint;
        end;

        TKontrol=record
        n, m, a, b:longint;
        end;

       { tmint=record
        t:int64;
        red:array of longint;
        end;  }

        tpath=record
        t:longint;
        nl:longint;
        p:array of tline;
        end;

        tgrad=record
        numl:longint;
        l:array[1..1000] of tline;
        end;



var k:tkontrol;
data:array[1..10000] of TLine;
//mint:array of tmint;
grad:array[1..10000] of tgrad;
a, b:array[1..10000] of tpath;
outnum:longint;

function Kontin(s:string):TKontrol;
var
ki, state, kod:integer;
nstr, mstr, astr, bstr:string;
tmp:tkontrol;
begin
state:=1;
for ki:=1 to length(s) do
        case state of
        1:if s[ki]=' ' then state:=state+1 else nstr:=nstr+s[ki];
        2:if s[ki]=' ' then state:=state+1 else mstr:=mstr+s[ki];
        3:if s[ki]=' ' then state:=state+1 else astr:=astr+s[ki];
        4:bstr:=bstr+s[ki];
        end;

val(nstr, tmp.n, kod);
val(mstr, tmp.m, kod);
val(astr, tmp.a, kod);
val(bstr, tmp.b, kod);
Kontin:=tmp;
end;

function Linein(s:string):TLine;
var
ki, state, kod:integer;
astr, bstr, tstr:string;
tmp:tline;
begin
state:=1;
for ki:=1 to length(s) do
        case state of
        1:if s[ki]=' ' then state:=state+1 else astr:=astr+s[ki];
        2:if s[ki]=' ' then state:=state+1 else bstr:=bstr+s[ki];
        3:tstr:=tstr+s[ki];
        end;

val(astr, tmp.lod, kod);
val(bstr, tmp.ldo, kod);
val(tstr, tmp.lag, kod);

Linein:=tmp;
end;

procedure Unos;
var f:text;
rd:string;
i, lot, ldt, llt:longint;
begin
assign(f, 'nishtel.in');
reset(f);
readln(f, k.n, k.m, k.a, k.b);
//for i:=1 to k.n do grad[i].numl:=0;
for i:=1 to k.m do
        begin
        readln(f, lot, ldt, llt);
        data[i].lod:=lot;
        data[i].ldo:=ldt;
        data[i].lag:=llt;
        grad[data[i].lod].numl:=grad[data[i].lod].numl+1;
        grad[data[i].lod].l[grad[data[i].lod].numl]:=data[i];
        end;

end;


function step(lok, curr, w, dragnl:longint; var dragpth:array of tline):tpath;
var i:longint;
begin
if curr=lok then
        if step.t>w then
        begin
        step.t:=w;
        step.nl:=dragnl;
        for i:=1 to dragnl do step.p[i]:=dragpth[i];
        end else
        for i:=1 to grad[curr].numl do
                begin
                dragpth[dragnl+1]:=grad[curr].l[i];
                step(lok, grad[curr].l[i].ldo, w+grad[curr].l[i].lag, dragnl+1, dragpth);
                end;

end;

function CanGo(sus:tline):boolean;
var i, j:longint;
tmp:boolean;
begin
tmp:=true;
for i:=1 to k.m do
        for j:=1 to a[i].nl do if (a[i].p[j].lod=sus.lod) and  (a[i].p[j].ldo=sus.ldo) and  (a[i].p[j].lod=sus.lag)
        then begin
        tmp:=false;
        break;
        end;
cango:=tmp;

end;



procedure Grind;
var i:longint;
f:text;
begin
outnum:=0;
for i:=1 to k.n do
        begin
        a[i]:=step(k.a, i, 0, 0, a[i].p);
        b[i]:=step(k.b, i, 0, 0, b[i].p);
        end;
for i:=1 to k.m do if CanGo(data[i]) then outnum:=outnum+1;
assign(f, 'nishtel.out');
rewrite(f);
Writeln(f, outnum);
end;

begin
Unos;
Grind;
end.


















