#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
const int inf = 1e9 + 100;
set<pair<int, int> > q;
bool mark[maxn];
int dis[maxn], W[maxn], ans;
pair<int, int> edge[maxn];
vector<pair<int, int> > v[maxn];
int n, m, s;
void RD_Mindis(int x) {
  for (int i = 1; i <= n; i++)
    if (i == x)
      dis[i] = 0;
    else
      dis[i] = inf;
  for (int i = 1; i <= n; i++) q.insert(make_pair(dis[i], i));
  while (q.size()) {
    int par = q.begin()->second;
    q.erase(q.begin());
    mark[par] = true;
    for (int i = 0; i < v[par].size(); i++) {
      int child = v[par][i].second;
      if (!mark[child]) {
        q.erase(make_pair(dis[child], child));
        dis[child] = min(dis[child], dis[par] + v[par][i].first);
        q.insert(make_pair(dis[child], child));
      }
    }
  }
}
int main() {
  cin >> n >> m >> s;
  for (int i = 1; i <= m; i++) {
    int fi, se, w;
    cin >> fi >> se >> w;
    v[fi].push_back(make_pair(w, se));
    v[se].push_back(make_pair(w, fi));
    edge[i] = make_pair(fi, se);
    W[i] = w;
  }
  int l;
  cin >> l;
  RD_Mindis(s);
  for (int i = 1; i <= n; i++)
    if (dis[i] == l) ans++;
  for (int i = 1; i <= m; i++) {
    int x = edge[i].first, y = edge[i].second;
    if (dis[x] < l and dis[y] < l and dis[x] + dis[y] + W[i] == 2 * l) ans++;
    if (dis[x] < l and l < dis[x] + W[i] and dis[y] + W[i] - (l - dis[x]) > l)
      ans++;
    if (dis[y] < l and l < dis[y] + W[i] and dis[x] + W[i] - (l - dis[y]) > l)
      ans++;
  }
  cout << ans << endl;
}
