#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5, inf = 2e8 + 10;
int n, m, s, l;
vector<pair<int, int>> graph[maxN];
int dist[maxN], prv[maxN];
set<pair<int, pair<int, int>>> done;
void dijkstra() {
  for (int i = 0; i < n; i++) dist[i] = inf;
  priority_queue<pair<int, int>> pq;
  pq.push({-(dist[s] = 0), s});
  while (!pq.empty()) {
    int u = pq.top().second, d = -pq.top().first;
    pq.pop();
    if (d > dist[u]) continue;
    for (auto &e : graph[u])
      if (dist[u] + e.second < dist[e.first])
        pq.push({-(dist[e.first] = dist[u] + e.second), e.first}),
            prv[e.first] = u;
  }
}
int main() {
  while (scanf("%d %d %d", &n, &m, &s) != EOF) {
    s--;
    for (int i = 0; i < n; i++) graph[i].clear();
    for (int i = 0; i < m; i++) {
      int u, v, w;
      scanf("%d %d %d", &u, &v, &w);
      u--, v--;
      graph[u].push_back({v, w}), graph[v].push_back({u, w});
    }
    scanf("%d", &l);
    dijkstra();
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (0)
        if (dist[i] != inf && dist[i] > l) printf("\t%d %d\n", i, dist[i]);
      if (0) {
        printf("\t%d %d:", i + 1, dist[i]);
        stack<int> a;
        for (int u = i; u != s; u = prv[u]) a.push(u);
        a.push(s);
        while (!a.empty()) {
          printf(" %d", a.top() + 1);
          a.pop();
        }
        printf("\n");
      }
      if (dist[i] == l) ans++;
      if (dist[i] < l) {
        for (auto &e : graph[i]) {
          if (dist[i] + e.second > l &&
              (dist[i] + dist[e.first] + e.second > 2 * l ||
               (dist[i] + dist[e.first] + e.second == 2 * l && i < e.first))) {
            if (0)
              printf("%d %d %d %d %d\n", i + 1, e.first + 1, dist[i],
                     dist[e.first], dist[i] + e.second);
            ans++;
          }
        }
      }
    }
    printf("%d\n", ans);
    if (0) printf("------------------\n");
  }
  return 0;
}
