#include <bits/stdc++.h>
using namespace std;
int n, m, s, l;
struct edge {
  int u, v, w;
  edge(int _u = 0, int _v = 0, int _w = 0) : u(_u), v(_v), w(_w) {}
};
vector<edge> E;
vector<vector<int> > g;
set<int> kl[10 + 100000];
set<pair<int, int> > q;
int dist[10 + 100000];
void solve() {
  memset(dist, 0x3f, sizeof(dist));
  q.insert(make_pair(dist[s] = 0, s));
  while (!q.empty()) {
    int du = q.begin()->first;
    int u = q.begin()->second;
    q.erase(q.begin());
    if (du > dist[u]) continue;
    for (unsigned i = 0; i < g[u].size(); ++i) {
      int x = g[u][i];
      int v = E[x].v;
      int len = E[x].w;
      if (dist[v] > du + len) {
        q.insert(make_pair(dist[v] = du + len, v));
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  s--;
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--;
    v--;
    g[u].push_back(E.size());
    E.push_back(edge(u, v, w));
    g[v].push_back(E.size());
    E.push_back(edge(v, u, w));
  }
  scanf("%d", &l);
  solve();
  int ans = 0, sum = 0;
  for (int i = 0; i < n; ++i)
    if (dist[i] == l) ans++;
  for (int u = 0; u < n; ++u) {
    for (unsigned i = 0; i < g[u].size(); ++i) {
      int x = g[u][i];
      int v = E[x].v;
      int len = E[x].w;
      if (dist[u] < l && dist[u] + len > l && dist[u] + dist[v] + len > 2 * l)
        ans++;
      if (dist[u] < l && dist[v] < l && dist[u] + dist[v] + len == 2 * l) sum++;
    }
  }
  printf("%d\n", ans + sum / 2);
  return 0;
}
