#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long, long long> > > v;
long long ka[100000];
long long et[100000];
int main() {
  for (long long i = 0; i < 100000; ++i) et[i] = -(1ll << 60);
  long long n, m, s;
  cin >> n >> m >> s;
  --s;
  v.resize(n);
  long long l;
  for (long long i = 0; i < m; ++i) {
    long long q, w, e;
    cin >> q >> w >> e;
    --q, --w;
    v[q].push_back(make_pair(w, e));
    v[w].push_back(make_pair(q, e));
  }
  cin >> l;
  priority_queue<pair<long long, long long> > pq;
  pq.push(make_pair(0, s));
  long long ma = 0;
  et[s] = 0;
  set<pair<long long, pair<long long, long long> > > lol;
  for (; pq.size();) {
    pair<long long, long long> q = pq.top();
    pq.pop();
    if (ka[q.second]) continue;
    if (et[q.second] > q.first) continue;
    if (-q.first == l) {
      ++ma;
      continue;
    }
    ka[q.second] = 1;
    for (long long i = 0; i < v[q.second].size(); ++i) {
      long long uk = v[q.second][i].first;
      long long up = q.first - v[q.second][i].second;
      if (up > et[uk] && !ka[uk]) {
        et[uk] = up;
        pq.push(make_pair(up, uk));
      }
    }
  }
  for (long long i = 0; i < v.size(); ++i) {
    for (long long j = 0; j < v[i].size(); ++j) {
      long long q = -et[i];
      long long qq = q;
      long long w = -et[v[i][j].first];
      long long ww = w;
      long long e = v[i][j].second;
      if (i > v[i][j].first) continue;
      if (q > w) swap(q, w);
      if (q >= l) {
        continue;
      }
      if (w >= l) {
        long long r = min(l - q, e);
        e -= r;
        q += r;
        if (e == 0) continue;
        ++ma;
      } else {
        e -= l - q;
        e -= l - w;
        if (e == 0) ++ma;
        if (e > 0) ma += 2;
      }
    }
  }
  cout << ma << '\n';
}
