#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > dijkstra;
list<int> graph[100010], weight[100010];
int dist[100010], x[100010], y[100010], z[100010];
int main() {
  int n, m, s, u, v, w, temp, l;
  cin >> n >> m >> s;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> w;
    x[i] = u, y[i] = v, z[i] = w;
    graph[u].push_back(v);
    graph[v].push_back(u);
    weight[u].push_back(w);
    weight[v].push_back(w);
  }
  cin >> l;
  for (int i = 1; i <= n; i++) {
    if (i == s) {
      dijkstra.insert(make_pair(0, i));
    } else {
      dijkstra.insert(make_pair(1000000000, i));
      dist[i] = 1000000000;
    }
  }
  pair<int, int> t;
  while (!dijkstra.empty()) {
    t = *dijkstra.begin();
    dijkstra.erase(*dijkstra.begin());
    dist[t.second] = t.first;
    list<int>::iterator i, j;
    for (i = graph[t.second].begin(), j = weight[t.second].begin();
         i != graph[t.second].end() && j != weight[t.second].end(); i++, j++) {
      temp = t.first + *j;
      if (temp < dist[*i]) {
        dijkstra.erase(make_pair(dist[*i], *i));
        dijkstra.insert(make_pair(temp, *i));
        dist[*i] = temp;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (dist[i] == l) {
      ans++;
    }
  }
  int flag;
  for (int i = 0; i < m; i++) {
    u = x[i], v = y[i], w = z[i];
    flag = -1;
    if (dist[u] < l && (l - dist[u] < w) && (w + dist[v] - l + dist[u] > l)) {
      ans++;
    }
    if (dist[v] < l && (l - dist[v] < w) && (w + dist[u] - l + dist[v] > l)) {
      ans++;
    }
    if (dist[u] < l && dist[v] < l && dist[u] + dist[v] + w == 2 * l) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
