#include <bits/stdc++.h>
using namespace std;
const int INFint = 2147483647;
const long long INF = 9223372036854775807ll;
const long long MOD = 1000000007ll;
const long double EPS = 1e-9;
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  int s;
  cin >> s;
  vector<vector<pair<int, int> > > g(n);
  for (int i = 0; i < m; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--, y--;
    g[x].push_back(make_pair(y, c));
    g[y].push_back(make_pair(x, c));
  }
  vector<int> d(n, INFint);
  s--;
  d[s] = 0;
  priority_queue<pair<int, int> > q;
  q.push(make_pair(0, s));
  while (!q.empty()) {
    int v = q.top().second;
    int dist = -q.top().first;
    q.pop();
    if (dist > d[v]) continue;
    for (int i = 0; i < g[v].size(); i++) {
      int to = g[v][i].first;
      int c = g[v][i].second;
      if (d[to] > d[v] + c) {
        d[to] = d[v] + c;
        q.push(make_pair(-d[to], to));
      }
    }
  }
  int l;
  cin >> l;
  int ans = 0;
  for (int v = 0; v < n; v++) {
    for (int i = 0; i < g[v].size(); i++) {
      int to = g[v][i].first;
      int w = g[v][i].second;
      if (d[v] < l && d[v] + w > l) {
        if (w - l + d[v] + d[to] > l) {
          ans += 2;
        } else {
          if (w - l + d[v] + d[to] == l) ans++;
        }
      }
    }
  }
  ans /= 2;
  for (int i = 0; i < n; i++) {
    if (d[i] == l) ans++;
  }
  cout << ans;
  fprintf(stderr, "\nTIME = %lf\n", 1.0 * clock() / CLOCKS_PER_SEC);
  return 0;
}
