#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;

void snp(int a, int n, int** g, bool** bg, int* d)
{
     for (int i=0; i < n; i++)
         {
              if (a==i) continue;
              for (int x=0; x<n; x++)
              {    if (x!=a){    
                       if (d[x]==-1) {if ( (g[a][i]!=-1)&&(g[i][x]!=-1) ) d[x]=i;}
                       else { 
                             if ( (g[a][i]!=-1)&&(g[i][x]!=-1) ) 
                                { 
                                  int l=g[a][i]+g[i][x];
                                  int r=g[a][ d[x] ]+ g[ d[x] ][x];
                                  if (l<r) d[x]=i;
                                }
                            }
                       
                  }
                  else
                      if (d[i]==-1) {if (g[a][i]!=-1) d[i]=i;}
                      else {int h;
                            if ( (h=(g[a][i]))!=-1 ) 
                               {
                                int r=g[a][d[i]]+g[d[i]][i];
                                if (h>r) d[i]=i;
                                }
                            }
                            
              }
              
         }
     //system("PAUSE");
     for (int i=0;i<n;i++)
         {//cout<<d[i]<<" ";
          bg[a][ d[i] ]=true;
          bg[ d[i] ][i]=true;}
    cout<<endl;
    //system("PAUSE");    
}


int main(int argc, char *argv[])
{
    ifstream in("nishtel.in");
            if (!in) return -1;
     
    int n;
    int m;
    int a,b;
    
    in>>n>>m>>a>>b;
    a--;
    b--;
    bool** bg = new bool* [n];
    int** g = new int* [n];
    
    int* da = new int [n];
    int* db = new int [n];
    
    for (int i=0;i<n;i++)
        {g[i] = new int [n];
         bg[i] = new bool [n];
         da[i]=-1;
         db[i]=-1;
         for (int j=0;j<n;j++)
             {
                  g[i][j]=-1;
                  bg[i][j]=false;        
             }
        }
   
   int br=0;

   { int ha,hb,hc;
    for (int i=0;i<m;i++)
        {in>>ha>>hb>>hc;
         ha--;
         hb--;
         if (g[ha][hb]==-1)
                            g[ha][hb]=hc;
         else {
               br++;
               if (g[ha][hb]<hc) g[ha][hb]=hc;
              }
        }
    }
    
    m-=br;
    
    da[a]=a;
    db[b]=b;
    
    snp(a,n,g,bg,da);
    snp(b,n,g,bg,db);
    
    int count=0;
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            if ((bg[i][j])&&(i!=j)) count++;
    ofstream out("nishtel.out");
    out<<br+m-count;
    //system("PAUSE");
    return EXIT_SUCCESS;
}
