#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, v, s, l;
vector<pair<int, int>> a[100010];
map<pair<int, int>, int> ck[100010];
int dis[100010];
void dk() {
  priority_queue<pair<int, int>> q;
  fill(dis, dis + 100009, 2e9);
  dis[s] = 0;
  q.push({0, s});
  while (q.size()) {
    int inx = q.top().second;
    q.pop();
    for (auto p : a[inx]) {
      if (dis[p.first] > dis[inx] + p.second) {
        dis[p.first] = dis[inx] + p.second;
        q.push({-dis[p.first], p.first});
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &v);
    a[x].push_back({y, v});
    a[y].push_back({x, v});
  }
  cin >> l;
  dk();
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (dis[i] == l) ans++;
    for (int j = 0; j <= a[i].size() - 1; j++)
      if (dis[a[i][j].first] + (a[i][j].second - (l - dis[i])) >= l &&
          ck[i].count({a[i][j].first, l - dis[i]}) == 0 && dis[i] < l &&
          a[i][j].second + dis[i] > l)
        ck[a[i][j].first][{i, a[i][j].second - (l - dis[i])}] = 1, ans++;
  }
  cout << ans;
  return 0;
}
