#include <bits/stdc++.h>
using namespace std;
const int V = 100005;
const int E = 200005;
int n, m, e, s, head[V], pnt[E], nxt[E], cost[E], vis[V], Q[V], dist[V];
void add(int u, int v, int c) {
  nxt[e] = head[u];
  head[u] = e;
  pnt[e] = v;
  cost[e] = c;
  e++;
}
const int inf = ~0u >> 2;
int hash[E];
void spfa() {
  Q[0] = s;
  memset(vis, 0, sizeof(vis));
  vis[s] = 1;
  for (int i = 0; i < n; i++) dist[i] = inf;
  dist[s] = 0;
  int front = 0, tail = 1;
  while (front < tail) {
    int u = Q[front++];
    vis[u] = 0;
    for (int i = head[u]; i != -1; i = nxt[i]) {
      int v = pnt[i];
      if (dist[v] > dist[u] + cost[i]) {
        dist[v] = dist[u] + cost[i];
        if (vis[v] == 0) {
          Q[tail++] = v;
          vis[v] = 1;
        }
      }
    }
  }
}
int main() {
  while (cin >> n >> m >> s) {
    s--;
    e = 0;
    memset(head, -1, sizeof(head));
    for (int i = 0; i < m; i++) {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      a--, b--;
      add(a, b, c);
      add(b, a, c);
    }
    int l;
    cin >> l;
    spfa();
    int ans = 0;
    for (int i = 0; i < n; i++)
      if (dist[i] == l) ans++;
    for (int i = 0; i < e; i += 2) {
      int x = pnt[i], y = pnt[i + 1], c = cost[i];
      int a = -1, b = -1;
      if (l - dist[x] > 0 && l - dist[x] < c) {
        int dis = l - dist[x];
        if (dist[y] + c - dis >= l) a = dis;
      }
      int dis = l - dist[y];
      if (l - dist[y] > 0 && l - dist[y] < c) {
        if (dist[x] + c - dis >= l) b = dis;
      }
      if (a == -1 && b == -1)
        continue;
      else if (a == -1 || b == -1)
        ans++;
      else if (a + b == c)
        ans++;
      else
        ans += 2;
    }
    cout << ans << endl;
  }
  return 0;
}
