#include <bits/stdc++.h>
using namespace std;
vector<int> myvec[100005], weight[100005];
int dist[100005], visited[100005], n, m;
priority_queue<pair<int, int> > pq;
pair<pair<int, int>, int> edge[100005];
void dijkstra(int s) {
  int i, j, k, w, sumvisited = 0;
  for (i = 1; i <= n; i++) {
    dist[i] = 2000000005;
    visited[i] = 0;
  }
  while (!pq.empty()) pq.pop();
  pq.push(make_pair(0, s));
  dist[s] = 0;
  while (sumvisited < n) {
    do {
      i = pq.top().second;
      pq.pop();
    } while (visited[i]);
    visited[i] = 1;
    sumvisited++;
    for (j = 0; j < myvec[i].size(); j++) {
      k = myvec[i][j];
      w = weight[i][j];
      if (dist[i] + w < dist[k]) {
        dist[k] = dist[i] + w;
        pq.push(make_pair(-1 * dist[k], k));
      }
    }
  }
}
int main() {
  int i, j, k, s, w, ans, l;
  scanf("%d %d %d", &n, &m, &s);
  for (i = 0; i < m; i++) {
    scanf("%d %d %d", &j, &k, &w);
    myvec[j].push_back(k);
    weight[j].push_back(w);
    myvec[k].push_back(j);
    weight[k].push_back(w);
    edge[i] = make_pair(make_pair(j, k), w);
  }
  dijkstra(s);
  scanf("%d", &l);
  for (ans = 0, i = 1; i <= n; i++)
    if (dist[i] == l) ans++;
  for (i = 0; i < m; i++) {
    j = dist[edge[i].first.first];
    k = dist[edge[i].first.second];
    w = edge[i].second;
    if (j > k) swap(j, k);
    if (j >= l) continue;
    if (j + w == k) {
      if (j < l && k > l) ans++;
    } else {
      if (j < l && k >= l) ans++;
      if (j < l && k < l) {
        int a, b;
        a = w - (k - j);
        b = 2 * (l - k);
        if (a == b) ans++;
        if (a > b) ans += 2;
      }
    }
  }
  printf("%d\n", ans);
  return 0;
}
