#include <bits/stdc++.h>
using namespace std;
struct Edge {
  long long v, w, next;
} e[400005];
long long n, m, s, num, l, h[100005], fa[100005], dis[100005], vis[100005];
long long u[100005], v[100005], w[100005];
double vis1[400005];
void insert(long long u, long long v, long long w) {
  e[++num].v = v, e[num].w = w;
  e[num].next = h[u], h[u] = num;
}
void bfs() {
  queue<long long> q;
  q.push(s);
  while (!q.empty()) {
    long long x = q.front();
    q.pop();
    for (long long i = h[x]; i; i = e[i].next) {
      long long v = e[i].v;
      if (v == fa[x] || v == s) continue;
      if (dis[v] > dis[x] + e[i].w || !dis[v]) {
        dis[v] = dis[x] + e[i].w;
        fa[v] = x;
        q.push(v);
      }
    }
  }
}
signed main() {
  scanf("%lld%lld%lld", &n, &m, &s);
  for (long long i = 1; i <= m; ++i) {
    scanf("%lld%lld%lld", &u[i], &v[i], &w[i]);
    insert(u[i], v[i], w[i]);
    insert(v[i], u[i], w[i]);
  }
  scanf("%lld", &l);
  bfs();
  long long ans = 0;
  for (long long i = 1; i <= n; ++i) {
    if (dis[i] == l) {
      ans++;
    }
  }
  for (long long i = 1; i <= m; ++i) {
    if (dis[u[i]] + w[i] == dis[v[i]]) {
      if (dis[u[i]] < l && dis[v[i]] > l) ans++;
    } else if (dis[v[i]] + w[i] == dis[u[i]]) {
      if (dis[v[i]] < l && dis[u[i]] > l) ans++;
    } else {
      if (dis[u[i]] < l && dis[v[i]] < l) {
        if (l - dis[u[i]] + l - dis[v[i]] == w[i])
          ans++;
        else {
          if (w[i] - (l - dis[u[i]]) + dis[v[i]] > l) ans++;
          if (w[i] - (l - dis[v[i]]) + dis[u[i]] > l) ans++;
        }
      } else if (dis[u[i]] < l) {
        if (dis[u[i]] + w[i] > l) ans++;
      } else if (dis[v[i]] < l) {
        if (dis[v[i]] + w[i] > l) ans++;
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}
