#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 100 + 10;
const long long INF = 1000LL * 1000 * 1000 * 1000 * 1000;
int n, m, cap;
vector<int> v[maxn];
vector<int> d[maxn];
long long dist[maxn];
void Add(int a, int b, int c) {
  v[a].push_back(b);
  d[a].push_back(c);
}
struct compare {
  bool operator()(const int& a, const int& b) {
    if (dist[a] != dist[b]) return dist[a] < dist[b];
    return a < b;
  }
};
set<int, compare> s;
long long l;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m >> cap;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    Add(a, b, c);
    Add(b, a, c);
  }
  cin >> l;
  s.insert(cap);
  for (int i = 1; i <= n; ++i) dist[i] = INF;
  dist[cap] = 0;
  while (!s.empty()) {
    int a = *s.begin();
    s.erase(s.begin());
    for (int i = 0; i < (int)v[a].size(); ++i) {
      int nei = v[a][i];
      long long cost = d[a][i];
      if (cost + dist[a] < dist[nei]) {
        if (s.find(nei) != s.end()) s.erase(s.find(nei));
        dist[nei] = cost + dist[a];
        s.insert(nei);
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (dist[i] == l) {
      ++ans;
      cerr << i << endl;
    } else if (dist[i] < l) {
      for (int j = 0; j < (int)v[i].size(); ++j) {
        int nei = v[i][j];
        long long cost = d[i][j];
        if (dist[i] + cost > l && dist[nei] + cost - (l - dist[i]) >= l) {
          ++ans;
          if (dist[nei] < l && i < nei && dist[nei] + cost - (l - dist[i]) == l)
            --ans;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
