#include <bits/stdc++.h>
using namespace std;
const int inv = 1000000000;
const int minv = -1000000000;
const int max_n = 100010;
int n, m, s, l;
vector<pair<int, int> > adjl[max_n];
bool burnt[max_n];
int ebt[max_n];
set<pair<int, int> >::iterator it;
set<pair<int, int> > S;
int res = 0;
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  scanf("%d", &s);
  --s;
  int u, v, w;
  for (int i = 0; i < m; ++i) {
    scanf("%d", &u);
    --u;
    scanf("%d", &v);
    --v;
    scanf("%d", &w);
    adjl[u].push_back(pair<int, int>(v, w));
    adjl[v].push_back(pair<int, int>(u, w));
  }
  scanf("%d", &l);
  S.clear();
  fill(burnt, burnt + n, false);
  fill(ebt, ebt + n, inv);
  ebt[s] = 0;
  for (int i = 0; i < n; ++i) S.insert(pair<int, int>(ebt[i], i));
  while (!S.empty()) {
    int vt = S.begin()->second;
    S.erase(S.begin());
    burnt[vt] = true;
    res += (ebt[vt] == l);
    int nb, wt;
    for (int i = 0; i < adjl[vt].size(); ++i) {
      nb = adjl[vt][i].first;
      wt = adjl[vt][i].second;
      if (ebt[nb] > ebt[vt] + wt) {
        S.erase(S.find(pair<int, int>(ebt[nb], nb)));
        ebt[nb] = ebt[vt] + wt;
        S.insert(pair<int, int>(ebt[nb], nb));
      }
    }
  }
  for (int u = 0; u < n; ++u) {
    for (int i = 0; i < adjl[u].size(); ++i) {
      int v = adjl[u][i].first;
      int w = adjl[u][i].second;
      if (u > v) continue;
      int x1 = l - ebt[u];
      bool y1 = false;
      if (0 < x1 and x1 < w and ebt[v] + w - x1 >= ebt[u] + x1) {
        ++res;
        y1 = true;
      }
      int x2 = l - ebt[v];
      bool y2 = false;
      if (0 < x2 and x2 < w and ebt[u] + w - x2 >= ebt[v] + x2) {
        ++res;
        y2 = true;
      }
      if (y1 and y2 and x1 + x2 == w) --res;
    }
  }
  printf("%d\n", res);
  return 0;
}
