#include <bits/stdc++.h>
using namespace std;
int v[100005], u[100005], w[100005], dist[100005];
vector<pair<int, int> > edges[100005];
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
int main() {
  int n, m, s, l;
  while (cin >> n >> m >> s) {
    for (int i = 0; i < m; ++i) {
      cin >> v[i] >> u[i] >> w[i];
      edges[v[i]].push_back(make_pair(u[i], w[i]));
      edges[u[i]].push_back(make_pair(v[i], w[i]));
    }
    cin >> l;
    pq.push(make_pair(0, s));
    memset(dist, 0x3f, sizeof(dist));
    dist[s] = 0;
    int c, d, nxt;
    while (pq.size()) {
      c = pq.top().second;
      pq.pop();
      for (int i = 0; i < edges[c].size(); ++i) {
        nxt = edges[c][i].first;
        if (dist[nxt] > dist[c] + edges[c][i].second) {
          dist[nxt] = dist[c] + edges[c][i].second;
          pq.push(make_pair(dist[nxt], nxt));
        }
      }
    }
    int tmp;
    int cnt = 0;
    for (int i = 1; i <= n; ++i)
      if (dist[i] == l) ++cnt;
    for (int i = 0; i < m; ++i) {
      if (dist[u[i]] < l && dist[u[i]] + w[i] > l) {
        tmp = dist[u[i]] + w[i];
        if (dist[v[i]] + tmp - l >= l) ++cnt;
      }
      if (dist[v[i]] < l && dist[v[i]] + w[i] > l) {
        tmp = dist[v[i]] + w[i];
        if (dist[u[i]] + tmp - l > l) ++cnt;
      }
    }
    cout << cnt << "\n";
    for (int i = 1; i <= n; ++i) edges[i].clear();
    while (pq.size()) pq.pop();
  }
  return 0;
}
