#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<long long int, long long int> > > edge;
vector<long long int> dist;
void dijkstra(long long int src) {
  dist[src] = 0;
  set<pair<long long int, long long int> > myst;
  myst.insert(make_pair(0, src));
  while (!myst.empty()) {
    pair<long long int, long long int> temp = *myst.begin();
    myst.erase(temp);
    for (auto it : edge[temp.second]) {
      if (dist[it.first] > dist[temp.second] + it.second) {
        if (dist[it.first] != LONG_MAX)
          myst.erase(myst.find(make_pair(dist[it.first], it.first)));
        dist[it.first] = dist[temp.second] + it.second;
        myst.insert(make_pair(dist[it.first], it.first));
      }
    }
  }
}
int main() {
  long long int n, m, src;
  cin >> n >> m >> src;
  edge.resize(n + 1);
  for (int i = 1; i <= m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edge[a].push_back(make_pair(b, c));
    edge[b].push_back(make_pair(a, c));
  }
  dist.assign(n + 1, LONG_MAX);
  dijkstra(src);
  int l;
  cin >> l;
  int ct = 0;
  for (int i = 1; i <= n; i++) {
    if (dist[i] == l) ct++;
  }
  int ct2 = 0;
  for (int i = 1; i <= n; i++) {
    for (auto it : edge[i]) {
      int u = i;
      int v = it.first;
      int c = it.second;
      if (dist[u] < l && l - dist[u] < c && dist[v] + c - (l - dist[u]) > l)
        ct2++;
      if (dist[v] < l && l - dist[v] < c && dist[u] + c - (l - dist[v]) > l)
        ct2++;
      if (dist[u] < l && dist[v] < l && dist[u] + dist[v] + c == 2 * l) ct2++;
    }
  }
  cout << ct + ct2 / 2 << "\n";
  return 0;
}
