#include <bits/stdc++.h>
using namespace std;
const int N = 100861;
const int oo = (1 << 28);
const double eps = 1e-6;
struct node {
  int v, w, d;
  bool operator<(const node& sec) const { return d > sec.d; }
} tmp1, tmp2, nodeu, nodev;
struct enode {
  int u, v, w;
} edge[N * 2];
vector<node> adj[N];
set<int> point[N];
int dis[N], vis[N];
void dijkstra(int s, int n) {
  priority_queue<node> pq;
  memset(vis, 0, sizeof(vis));
  fill(dis + 1, dis + n + 1, oo);
  dis[s] = 0;
  nodeu.v = s, nodeu.d = 0;
  pq.push(nodeu);
  while (!pq.empty()) {
    nodeu = pq.top();
    pq.pop();
    int u = nodeu.v;
    vis[u] = 1;
    for (int i = 0; i < (int)adj[u].size(); i++) {
      int v = adj[u][i].v, w = adj[u][i].w;
      if (dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        nodev.d = dis[v];
        nodev.v = v;
        pq.push(nodev);
      }
    }
  }
}
int main() {
  int n, m, s, l, u, v, w;
  while (scanf("%d %d %d", &n, &m, &s) == 3) {
    for (int i = 0; i <= n; i++) adj[i].clear();
    for (int i = 0; i < m; i++) point[i].clear();
    for (int i = 0; i < m; i++) {
      scanf("%d %d %d", &u, &v, &w);
      edge[i].u = u, edge[i].v = v, edge[i].w = w;
      edge[i + m].u = v, edge[i + m].v = v, edge[i + m].w = w;
      tmp1.v = v, tmp1.w = w;
      tmp2.v = u, tmp2.w = w;
      adj[u].push_back(tmp1);
      adj[v].push_back(tmp2);
    }
    scanf("%d", &l);
    int ans = 0;
    dijkstra(s, n);
    for (int i = 1; i <= n; i++)
      if (dis[i] == l) ans++;
    for (int i = 0; i < m; i++) {
      u = edge[i].u, v = edge[i].v, w = edge[i].w;
      if (dis[u] < l && dis[u] + w > l) {
        int posion = l - dis[u];
        int rposion = w - posion;
        if (dis[u] + posion <= dis[v] + rposion) {
          if (point[i].find(posion) == point[i].end()) point[i].insert(posion);
        }
      }
      if (dis[v] < l && dis[v] + w > l) {
        int posion = w - (l - dis[v]);
        int rposion = w - posion;
        if (dis[v] + rposion <= dis[u] + posion) {
          if (point[i].find(posion) == point[i].end()) point[i].insert(posion);
        }
      }
    }
    for (int i = 0; i < m; i++) {
      ans += point[i].size();
    }
    printf("%d\n", ans);
  }
  return 0;
}
