#include <bits/stdc++.h>
using namespace std;
const int infint = INT_MAX;
const long long infll = LLONG_MAX;
const int MAX = 1e5 + 10;
long long dist[MAX];
vector<pair<int, int> > adj[MAX];
int main() {
  fill((long long*)dist, (long long*)dist + MAX, 1e12);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, s;
  cin >> n >> m >> s;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  long long l;
  cin >> l;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  q.push({0, s});
  dist[s] = 0;
  while (q.size()) {
    int v = q.top().second;
    long long d = q.top().first;
    q.pop();
    if (dist[v] != 0 && dist[v] < d) continue;
    for (auto i : adj[v]) {
      if (d + i.second < dist[i.first]) {
        dist[i.first] = d + i.second;
        q.push({d + i.second, i.first});
      }
    }
  }
  int h = 0, cnt = 0, oCnt = 0;
  for (int i = 1; i <= n; i++) {
  }
  for (int i = 1; i <= n; i++) {
    if (dist[i] == l) h++;
    for (auto j : adj[i]) {
      int dstLeft = l - dist[i];
      if (dstLeft <= 0 || dstLeft >= j.second) continue;
      int dstToI = dstLeft;
      int dstToJ = j.second - dstToI;
      if (dstToJ + dist[j.first] < l) {
        continue;
      } else if (dstToJ + dist[j.first] == l) {
        oCnt++;
      } else {
        cnt++;
      }
    }
    cout << "\n";
  }
  cout << h + cnt + (oCnt / 2);
  return 0;
}
