#include<stdio.h>
#include<list>
#include<queue>

using namespace std;

#define MAXN 100000
#define INF -1

FILE* f;

int n, m, a, b;

list<pair<int, int> > v[MAXN];
list<pair<int, int> > rv[MAXN];

priority_queue<pair<int, int> > hip;

int ca[MAXN];
int cb[MAXN];

int i;

list<pair<int, int> >::iterator it;

int res;

int main()
{
 f = fopen("nishtel.in", "r");
 
 fscanf(f, "%d%d%d%d", &n, &m, &a, &b);
 
 a--;
 b--;
 
 for(i = 0; i < m; i++)
 {
  int p, q, t;
  
  fscanf(f, "%d%d%d", &p, &q, &t); 
    
  p--;
  q--;
  
  v[p].push_back(make_pair(q, t));
  rv[q].push_back(make_pair(p, t));
 } 
 
 for(i = 0; i < n; i++)
  cb[i] = INF;
 
 cb[b] = 0;
 
 hip.push(make_pair(0,b));
 
 
 while(!hip.empty())
 {
  int tc = hip.top().second;
  
  hip.pop();  
  
  for(it = v[tc].begin(); it != v[tc].end(); it++)
   if(cb[it->first] == INF || cb[tc] + it->second < cb[it->first])
   {
    cb[it->first] = cb[tc] + it->second;
    hip.push(make_pair(-cb[it->first], it->first));
   } 
 }
 
 /*
 for(i = 0; i < n; i++)
  printf("%d ", cb[i]);
 
 getchar();
 */
 
 for(i = 0; i < n; i++)
  ca[i] = INF;
 
 ca[a] = 0;
 
 hip.push(make_pair(0,a));
 
 while(!hip.empty())
 {
  int tc = hip.top().second;
  
  hip.pop();  
  
  for(list<pair<int, int> >::iterator it = v[tc].begin(); it != v[tc].end(); it++)
   if(ca[it->first] == INF || ca[tc] + it->second < ca[it->first])
   {
    ca[it->first] = ca[tc] + it->second;
    hip.push(make_pair(-ca[it->first], it->first));
   } 
 }
 
 /*
 for(i = 0; i < n; i++)
  printf("%d ", ca[i]);
 
 getchar();
 */
 
 for(i = 0; i < n; i++)
 {
  
   for(it = rv[i].begin(); it != rv[i].end() && !(ca[it->first] + it->second == ca[i] && cb[it->first] + it->second == cb[i]); it++);
   
   if(it != rv[i].end())
   {
    res += rv[i].size() - 1;
   }
   else
    res += rv[i].size() - 2;
    
 }
 
 f = fopen("nishtel.out", "w");
 
 fprintf(f, "%d", res + 2);
 
 return 0;
}
