#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n, m, s;
int targ;
vector<pair<int, int> > v[MAXN];
vector<pair<int, pair<int, int> > > edges;
int dist[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> s;
  s--;
  for (int i = 0; i < m; i++) {
    int a, b, d;
    cin >> a >> b >> d;
    a--;
    b--;
    v[a].push_back(pair<int, int>(b, d));
    v[b].push_back(pair<int, int>(a, d));
    edges.push_back(pair<int, pair<int, int> >(d, pair<int, int>(a, b)));
  }
  cin >> targ;
  for (int i = 0; i < n; i++) {
    dist[i] = 1 << 30;
  }
  dist[s] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  pq.push(pair<int, int>(0, s));
  while (pq.size()) {
    int cur = pq.top().second;
    int dst = pq.top().first;
    pq.pop();
    if (dst != dist[cur]) continue;
    for (int i = 0; i < v[cur].size(); i++) {
      int nxt = v[cur][i].first;
      int d = v[cur][i].second;
      if (dist[nxt] > dst + d) {
        dist[nxt] = dst + d;
        pq.push(pair<int, int>(dist[nxt], nxt));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (dist[i] == targ);
  }
  for (int i = 0; i < m; i++) {
    int a = edges[i].second.first, b = edges[i].second.second;
    int d = edges[i].first;
    bool ba = (dist[a] < targ && targ < dist[a] + d) &&
              (targ <= dist[b] + d - (targ - dist[a]));
    bool bb = (dist[b] < targ && targ < dist[b] + d) &&
              (targ <= dist[a] + d - (targ - dist[b]));
    if ((ba && !bb) || (!ba && bb)) {
      ans++;
    } else if (ba && bb) {
      ans += (2 * targ - dist[a] - dist[b] == d ? 1 : 2);
    }
  }
  cout << ans << '\n';
}
