type graf = record p,d,t,pok: longint;end;
var i,j,x,y,n,m,a,b,t,p,k: longint;
    g: array[0..200000] of graf;
    da,db,idx,posl: array[0..10000] of longint;
    froma,fromb: array[0..10000] of longint;//slog;
    q: array[0..20000] of integer;
    bo: array[0..10000] of boolean;
    be: array[-1..100000] of boolean;
    c: char;
begin
     assign(input,'nishtel.in');
     reset(input);
     readln(n,m,a,b);
     for i:=1 to m do
      begin
       x:=0;y:=0;t:=0;
       read(c);
       while c<>' ' do
        begin
         x:=x*10+ord(c)-ord('0');
         read(C);
        end;
       read(c);
       while c<>' ' do
        begin
         y:=y*10+ord(c)-ord('0');
         read(C);
        end;
       read(c);
       while (c<>' ') and (not eoln) do
        begin
         t:=t*10+ord(c)-ord('0');
         read(C);
        end;
       t:=t*10+ord(c)-ord('0');
       readln;
       g[i].p:=x;
       g[i].d:=y;
       g[i].t:=t;
       if idx[x]=0 then idx[x]:=i;
       g[posl[x]].pok:=i;
       posl[x]:=i;
      end;
     close(input);
     bo[a]:=true;
     for i:=1 to n do da[i]:=maxlongint;
     for i:=1 to n do froma[i]:=-1;
     da[a]:=0;
     p:=1;
     k:=2;
     q[1]:=a;
     while p<>k do
      begin
       x:=q[p];
       j:=idx[x];
       while j<>0 do
        begin
         if (da[g[j].d]>da[g[j].p]+g[j].t) then
          begin
           da[g[j].d]:=da[g[j].p]+g[j].t;
           froma[g[j].d]:=j;
           be[j]:=true;
           bo[g[j].d]:=false;
          end;
         if not bo[g[j].d] then
          begin
           q[k]:=g[j].d;
           bo[g[j].d]:=true;
           k:=k+1;
          end;
         j:=g[j].pok;
        end;
       p:=p+1;
      end;
     fillchar(bo,sizeof(b),false);
     bo[b]:=true;
     for i:=1 to n do db[i]:=maxlongint;
     for i:=1 to n do fromb[i]:=-1;
     db[b]:=0;
     p:=1;
     k:=2;
     q[1]:=b;
     while p<>k do
      begin
       x:=q[p];
       j:=idx[x];
       while j<>0 do
        begin
         if db[g[j].d]>db[g[j].p]+g[j].t then
          begin
           db[g[j].d]:=db[g[j].p]+g[j].t;
           if db[g[j].d]+da[b]=da[g[j].d] then froma[g[j].d]:=j;
           be[j]:=true;
           fromb[g[j].d]:=j;
           bo[g[j].d]:=false;
          end;
         if not bo[g[j].d] then
          begin
           q[k]:=g[j].d;
           bo[g[j].d]:=true;
           k:=k+1;
          end;
         j:=g[j].pok;
        end;
       p:=p+1;
      end;
     x:=0;
     fillchar(be,sizeof(be),false);
     for i:=1 to n do
      begin
       if i<>a then
        begin
         if not be[froma[i]] then
          begin
           be[froma[i]]:=true;
           x:=x+1;
          end;
        end;
       if i<>b then
        begin
         if not be[fromb[i]] then
          begin
           be[fromb[i]]:=true;
           x:=x+1;
          end;
        end;
      end;
     assign(output,'nishtel.out');
     rewrite(output);
     writeln(m-x);
     close(output);
end.




