#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;
struct grana
{
       int kraj,t;
       int ind;
};
struct heap_entry
{
       int grad,ind;
       long long zbir;
       bool operator < (heap_entry b) const
       {
            return zbir>b.zbir;
       }
};
vector <grana> graf[10000];
vector <grana> obrnut[10000];
long long mini [10000];
int mindosao[10000];
int brisanje [100000];
vector <int> sacuvaj1[10000];
vector <int> sacuvaj2[10000];
int main ()
{
    for (int i=0;i<10000;i++)
    {
        mini[i]=-1;
        mindosao[i]=-1;
        brisanje[i]=0;
        sacuvaj1[i].clear();
        sacuvaj2[i].clear();
    }
    FILE *f=fopen("nishtel.in","r");
    int n,m,A,B;
    fscanf(f,"%d %d %d %d",&n,&m,&A,&B);
    A--;
    B--;
    for (int i=0;i<m;i++)
    {
        int p,k,t;
        fscanf(f,"%d %d %d",&p,&k,&t);
        p--;
        k--;
        grana nova; nova.kraj=k;nova.t=t;nova.ind=i;
        graf[p].push_back(nova);
        nova.kraj=p;
        obrnut[k].push_back(nova);
    }
    priority_queue<heap_entry> q;
    heap_entry poc;
    poc.grad=A;
    poc.zbir=0;
    poc.ind=-1;
    q.push(poc);
    while (!q.empty())
    {
          heap_entry tren=q.top();
          q.pop();
          //printf("stigao na %d %lld \n",tren.grad,tren.zbir);
          if (mini[tren.grad]==-1)
          {
                                  
              mini [tren.grad]=tren.zbir;
              mindosao[tren.grad]=tren.ind;
              for (int i=0;i<graf[tren.grad].size();i++)
              {
                  heap_entry novi;
                  novi.grad=graf[tren.grad][i].kraj;
                  novi.zbir=tren.zbir+graf[tren.grad][i].t;
                  novi.ind=graf[tren.grad][i].ind;
                  q.push(novi);
              }
          }
          else
          {
              brisanje[tren.ind]++;
              if (tren.zbir==mini[tren.grad])
              {
                sacuvaj1[tren.grad].push_back(tren.ind);
                if(mindosao[tren.grad]!=-2) {sacuvaj1[tren.grad].push_back(mindosao[tren.grad]);brisanje[mindosao[tren.grad]]++;mindosao[tren.grad]=-2;}
              }
          }
    }
    poc.grad=B;
    poc.zbir=0;
    poc.ind=-1;
    q.push(poc);
    for (int i=0;i<10000;i++) {mini[i]=-1;mindosao[i]=-1;}
    while (!q.empty())
    {
          heap_entry tren=q.top();
          q.pop();
          if (mini[tren.grad]==-1)
          {
              mini [tren.grad]=tren.zbir;
              mindosao[tren.grad]=tren.ind;
              for (int i=0;i<graf[tren.grad].size();i++)
              {
                  heap_entry novi;
                  novi.grad=graf[tren.grad][i].kraj;
                  novi.zbir=tren.zbir+graf[tren.grad][i].t;
                  novi.ind=graf[tren.grad][i].ind;
                  q.push(novi);
              }
          }
          else
          {
              brisanje[tren.ind]++;
              if (tren.zbir==mini[tren.grad])
              {
                sacuvaj2[tren.grad].push_back(tren.ind);
                if(mindosao[tren.grad]!=-2) {sacuvaj2[tren.grad].push_back(mindosao[tren.grad]);brisanje[mindosao[tren.grad]]++;mindosao[tren.grad]=-2;}
              }
          }
    }
    int res=0;
    for (int i=0;i<m;i++)
    {
        if (brisanje[i]==2) res++;
    }
    for (int i=0;i<n;i++)
    {
        bool svi1=true;
        if (sacuvaj1[i].size()==0) svi1=false;
        for (int j=0;j<sacuvaj1[i].size();j++)
        {
            if (brisanje[sacuvaj1[i][j]]!=2) svi1=false;
        }
        bool svi2=true;
        if (sacuvaj2[i].size()==0) svi2=false;
        for (int j=0;j<sacuvaj2[i].size();j++)
        {
            if (brisanje[sacuvaj2[i][j]]!=2) svi2=false;
        }
        if (svi1)
        {
                 if (!svi2) res--;
                 else
                 {
                     sort (sacuvaj1[i].begin(),sacuvaj1[i].end());
                     sort (sacuvaj2[i].begin(),sacuvaj2[i].end());
                     int i1=0,i2=0;
                     bool isti=false;
                     while (i1<sacuvaj1[i].size() && i2<sacuvaj2[i].size() && !isti)
                     {
                           if (sacuvaj1[i][i1] == sacuvaj2[i][i2]) isti=true;
                           else
                           {
                               if (sacuvaj1[i][i1] < sacuvaj2[i][i2]) i1++;
                               else i2++;
                           }
                     }
                     if (isti) res--;
                     else res-=2;
                 }
        }
        else if (svi2) res--;
    }
    FILE *g=fopen("nishtel.out","w");
    fprintf(g,"%d\n",res);
}
