#include <bits/stdc++.h>
using namespace std;
int x[100001], y[100001], w[100001], d[100001], t, D, ans, l, v, X, Y, n, m, s;
vector<pair<int, int> > e[100001];
bool vis[100001];
inline void init() {
  for (int i = 0; i <= n; i++) e[i].clear();
  memset(vis, false, sizeof(vis));
}
int main() {
  while (scanf("%d%d%d", &n, &m, &s) != EOF) {
    init();
    for (int i = 0; i < m; ++i) {
      scanf("%d%d%d", &x[i], &y[i], &w[i]);
      e[x[i]].push_back(make_pair(w[i], y[i]));
      e[y[i]].push_back(make_pair(w[i], x[i]));
    }
    scanf("%d", &l);
    priority_queue<pair<int, int>, vector<pair<int, int> >,
                   greater<pair<int, int> > >
        q;
    fill(d, d + n + 1, 0xf000000);
    q.push(make_pair((d[s] = 0), s));
    while (!q.empty()) {
      v = q.top().second;
      D = q.top().first;
      q.pop();
      if (vis[v])
        continue;
      else
        vis[v] = 1;
      vector<pair<int, int> >::iterator p;
      for (p = e[v].begin(); p != e[v].end(); p++)
        if (!vis[p->second]) {
          if ((t = D + p->first) < d[p->second]) {
            d[p->second] = t;
            q.push(make_pair(t, p->second));
          }
        }
    }
    ans = 0;
    for (int i = 1; i <= n; ++i)
      if (d[i] == l) ans++;
    for (int i = 0; i < m; ++i) {
      X = d[x[i]];
      Y = d[y[i]];
      if (X >= l && Y >= l) continue;
      if (X < l && Y < l) {
        if (abs(X - Y) - w[i] && (t = X + Y + w[i] - l * 2) >= 0)
          ans += t > 0 ? 2 : 1;
      } else
        ans += X > l || Y > l || abs(X - Y) - w[i];
    }
    printf("%d\n", ans);
  }
  return 0;
}
