#include <bits/stdc++.h>
using namespace std;
class yal {
 public:
  long long int w, mw;
  unsigned int mabda, maghsad;
  const bool operator<(const yal &io) const {
    if (mw != io.mw) return mw < io.mw;
    if (w != io.w) return w < io.w;
    if (mabda != io.mabda) return mabda < io.mabda;
    return maghsad < io.maghsad;
  }
  const bool operator==(const yal &io) const {
    return (w == io.w && mw == io.mw && mabda == io.mabda &&
            maghsad == io.maghsad);
  }
};
class ras {
 public:
  vector<yal> e;
  bool visit;
  long long int faseleh;
  ras() { visit = false; }
};
vector<ras> graph;
set<yal> rahha;
void pushing() {
  yal lop;
  cin >> lop.mabda >> lop.maghsad >> lop.w;
  lop.mabda--;
  lop.maghsad--;
  lop.mw = lop.w;
  graph[lop.mabda].e.push_back(lop);
  swap(lop.mabda, lop.maghsad);
  graph[lop.mabda].e.push_back(lop);
}
bool aya(yal kk, long long int d) {
  if (graph[kk.mabda].faseleh > d - 1 || graph[kk.mabda].faseleh + kk.w < d + 1)
    return 0;
  if (graph[kk.maghsad].faseleh > d) return 1;
  if (graph[kk.maghsad].faseleh + graph[kk.mabda].faseleh - 2 * d + kk.w > 0)
    return 1;
  if (graph[kk.maghsad].faseleh + graph[kk.mabda].faseleh - 2 * d + kk.w == 0 &&
      kk.mabda < kk.maghsad)
    return 1;
  return 0;
}
void adding() {
  long long int esm_maghsad = (*rahha.begin()).maghsad,
                esm_mabda = (*rahha.begin()).mabda;
  graph[esm_maghsad].visit = true;
  graph[esm_maghsad].faseleh = (*rahha.begin()).mw;
  for (unsigned int i = 0; i < graph[esm_maghsad].e.size(); i++) {
    yal lop = graph[esm_maghsad].e[i];
    lop.mw += (*rahha.begin()).mw;
    rahha.insert(lop);
  }
}
unsigned long long int N, M, S, K, B = 0;
void djkasra() {
  yal lop;
  lop.mw = 0;
  lop.w = 0;
  lop.mabda = S;
  lop.maghsad = S;
  rahha.insert(lop);
  while (!rahha.empty()) {
    if (!graph[(*rahha.begin()).maghsad].visit) adding();
    if (aya((*rahha.begin()), K)) {
      B++;
    }
    rahha.erase(*rahha.begin());
  }
  for (int i = 0; i < N; i++)
    if ((graph[i].faseleh == K)) B++;
  cout << B;
}
int main() {
  cin >> N >> M >> S;
  S--;
  graph.resize(N);
  for (int i = 0; i < M; i++) pushing();
  cin >> K;
  djkasra();
}
