#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100 * 1000 + 10;
int n, m, s, l, d[Maxn], ans;
vector<int> adj[Maxn], w[Maxn];
set<pair<int, int> > mys;
void dijkstra() {
  for (int i = 0; i < n; i++) {
    if (i != s) {
      d[i] = INT_MAX;
      mys.insert(make_pair(INT_MAX, i));
    }
  }
  mys.insert(make_pair(0, s));
  for (int i = 0; i < n; i++) {
    int v = mys.begin()->second;
    mys.erase(mys.begin());
    for (int j = 0; j < adj[v].size(); j++) {
      if (d[adj[v][j]] > d[v] + w[v][j]) {
        mys.erase(make_pair(d[adj[v][j]], adj[v][j]));
        d[adj[v][j]] = d[v] + w[v][j];
        mys.insert(make_pair(d[adj[v][j]], adj[v][j]));
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  s--;
  int u, v, wei;
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &u, &v, &wei);
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
    w[u].push_back(wei);
    w[v].push_back(wei);
  }
  scanf("%d", &l);
  dijkstra();
  for (int i = 0; i < n; i++) {
    if (d[i] == l) ans++;
    for (int j = 0; j < adj[i].size(); j++) {
      if (adj[i][j] > i) {
        if (d[i] < l && d[i] + w[i][j] > l && d[adj[i][j]] < l &&
            d[adj[i][j]] + w[i][j] > l) {
          int d2 = d[adj[i][j]] + w[i][j] - (l - d[i]);
          if (d2 >= l) ans++;
          if (d2 != l) {
            int d3 = d[i] + w[i][j] - (l - d[adj[i][j]]);
            if (d2 >= l) ans++;
          }
        } else {
          if (d[i] < l && d[i] + w[i][j] > l) {
            int d2 = d[adj[i][j]] + w[i][j] - (l - d[i]);
            if (d2 >= l) ans++;
          } else {
            if (d[adj[i][j]] < l && d[adj[i][j]] + w[i][j] > l) {
              int d2 = d[i] + w[i][j] - (l - d[adj[i][j]]);
              if (d2 >= l) ans++;
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
