#include <bits/stdc++.h>
using namespace std;
double eps = 1e-9;
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, s;
  scanf("%d %d %d", &n, &m, &s);
  s--;
  vector<vector<int>> g(n), w(n);
  vector<pair<pair<int, int>, int>> e;
  for (int i = 0; i < (int)(m); ++i) {
    int x, y, len;
    scanf("%d %d %d", &x, &y, &len);
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
    w[x].push_back(len);
    w[y].push_back(len);
    e.push_back({{x, y}, len});
  }
  int dist;
  scanf("%d", &dist);
  vector<int> d(n, INF);
  d[s] = 0;
  priority_queue<pair<int, int>> q;
  q.push({0, s});
  while (!q.empty()) {
    int v = q.top().second, curDist = -q.top().first;
    q.pop();
    if (curDist > d[v]) continue;
    for (int i = 0; i < (int)(g[v].size()); ++i) {
      int to = g[v][i], len = w[v][i];
      if (d[to] > d[v] + len) {
        d[to] = d[v] + len;
        q.push({-d[to], to});
      }
    }
  }
  int ans = 0;
  for (int v = 0; v < (int)(n); ++v)
    if (d[v] == dist) ans++;
  for (int i = 0; i < (int)(m); ++i) {
    int x = d[e[i].first.first], y = d[e[i].first.second], len = e[i].second;
    if (x > y) swap(x, y);
    int a = dist - x;
    if (a <= 0 || a >= len) continue;
    if (y + len - a >= dist) ans++;
    int b = dist - y;
    if (b <= 0 || b >= len || a == len - b) continue;
    if (x + len - b >= dist) ans++;
  }
  cout << ans << endl;
}
