#include <bits/stdc++.h>
using namespace std;
const int N = 1e6, oo = 1e9 + 7;
void home() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
struct cmp {
  bool operator()(pair<int, int> con, pair<int, int> cha) {
    return cha.first < con.first;
  }
};
multiset<pair<int, int> > heap;
int n, d[N], l, m;
bool tham[N];
struct ds {
  int u, v, w;
};
ds c[N];
vector<pair<int, int> > g[N];
void dijsktra(int s) {
  for (int i = (1); i <= (n); ++i) tham[i] = false, d[i] = oo;
  d[s] = 0;
  heap.insert(make_pair(0, s));
  while (!heap.empty()) {
    pair<int, int> tmp = *heap.begin();
    heap.erase(heap.begin());
    int u = tmp.second, w = tmp.first, k = g[u].size();
    if (!tham[u]) {
      tham[u] = true;
      for (int i = (0); i <= (k - 1); ++i) {
        pair<int, int> tmp = g[u][i];
        int v = tmp.first, w = tmp.second;
        if (d[v] > d[u] + w && !tham[v])
          d[v] = d[u] + w, heap.insert(make_pair(d[v], v));
      }
    }
  }
  int res = 0;
  for (int i = (1); i <= (n); ++i)
    if (d[i] == l) res++;
  for (int i = (1); i <= (m); ++i) {
    ds tmp = c[i];
    int u = tmp.u, v = tmp.v, w = tmp.w;
    if (d[u] < l && w > l - d[u] && d[v] + w - (l - d[u]) >= l) res++;
    if (d[v] < l && w > l - d[v] && d[u] + w - (l - d[v]) > l) res++;
  }
  cout << res;
}
int main() {
  home();
  int s;
  cin >> n >> m >> s;
  for (int i = (1); i <= (m); ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    c[i] = {u, v, w};
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  cin >> l;
  dijsktra(s);
}
