#include<stdio.h>
#include<vector>
using namespace std;


struct grana
{
       int g,t,s;       
};

int x;
vector <grana> a[10000];
struct doso
{
  int a,i,t;     
};
doso b[10000];
void back(doso k, int cilj)
{ 
     if(a[k.a][k.i].s==1) x++;
     a[k.a][k.i].s--;
     //back(b[k.a],cilj);
     
}

void idi(int na,int n)
{
     vector <int> c;
    c.push_back(na);
    int i;
    for(i=0;i<=n;i++) b[i].t=-1;
    b[na].t=0;
    for (i=0;i<c.size();i++)
    {
        for (int j=0;j<a[c[i]].size();j++)
        {
            if (b[c[i]].t+a[c[i]][j].t<=b[a[c[i]][j].g].t || b[a[c[i]][j].g].t==-1)
            {
                   if( b[a[c[i]][j].g].t!=-1) back(b[a[c[i]][j].g],na);
                   a[c[i]][j].s++;
                   if(a[c[i]][j].s==1) x--;                                      
                   c.push_back(a[c[i]][j].g);
                   b[a[c[i]][j].g].t=b[c[i]].t+a[c[i]][j].t;
                   b[a[c[i]][j].g].a=c[i];
                   b[a[c[i]][j].g].i=j;
                  
            }
            
        }                  
    }     
}


/*void idi(int start,int s)
{
          
}*/

int main()
{
    FILE *f,*g;
    f=fopen("nishtel.in","r");
    g=fopen("nishtel.out","w");
    int n,m,na,nb,i;
    fscanf(f,"%d %d %d %d",&n,&m,&na,&nb);
    x=m;
    //for(i=0;i<m;i++) a[i].push_back(0);
    for(i=0;i<m;i++)
    {
                    int pa,pb,pt;
                    fscanf(f,"%d %d %d",&pa,&pb,&pt);
                    grana p;
                    p.g=pb;p.t=pt;p.s=0;
                    a[pa].push_back(p);
                                    
    }
    idi(na,n);idi(nb,n);
    
    
    
    
    fprintf(g,"%d\n",x);
    //for(i=1;i<=n;i++) fprintf(g,"%d %d %d\n", b[i].a,b[i].i,b[i].t);
    
    fclose(f);
    fclose(g);
    
    
    
    
}
