#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v, w;
};
const int oo = (int)1e9 + 7;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    pq;
edge e[100005];
int d[100005];
vector<pair<int, int> > adj[100005];
int n, m, s, l, ans;
void dijkstra() {
  pair<int, int> top, v;
  int u, len;
  for (int i = 1; i <= n; i++) d[i] = oo;
  d[s] = 0;
  pq.push(pair<int, int>(0, s));
  while (!pq.empty()) {
    top = pq.top();
    pq.pop();
    if (top.first != d[top.second]) continue;
    len = top.first;
    u = top.second;
    for (int i = 0; i < (int)adj[u].size(); i++) {
      v = adj[u][i];
      if (d[v.first] > d[u] + v.second) {
        d[v.first] = d[u] + v.second;
        pq.push(pair<int, int>(d[v.first], v.first));
      }
    }
  }
}
void solve() {
  int x, y, u, v;
  for (int i = 1; i <= n; i++)
    if (d[i] == l) ans++;
  for (int i = 0; i < m; i++) {
    u = e[i].u;
    v = e[i].v;
    x = y = oo;
    if (d[v] + e[i].w > d[u] && d[u] < l) {
      x = l - d[u];
      if (x >= e[i].w || e[i].w - x + d[v] < l) x = oo;
    }
    if (d[u] + e[i].w > d[v] && d[v] < l) {
      y = e[i].w - (l - d[v]);
      if (y <= 0 || y + d[u] < l) y = oo;
    }
    if (x != oo) ans++;
    if (y != oo && y != x) ans++;
  }
  printf("%d\n", ans);
}
int main() {
  int u, v, w;
  if (0) {
    freopen("a.inp", "r", stdin);
  };
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
    adj[e[i].u].push_back(pair<int, int>(e[i].v, e[i].w));
    adj[e[i].v].push_back(pair<int, int>(e[i].u, e[i].w));
  }
  scanf("%d", &l);
  dijkstra();
  solve();
}
