#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, s, m, l;
vector<pair<int, int>> adj[N];
int dist[N], par[N];
void spath() {
  for (int i = 1; i <= n; i++) dist[i] = INT_MAX;
  priority_queue<int, vector<int>, greater<int>> pq;
  dist[s] = 0;
  pq.push(s);
  while (!pq.empty()) {
    int top = pq.top();
    pq.pop();
    for (auto xx : adj[top]) {
      int tmp = dist[top] + xx.second;
      if (dist[xx.first] > tmp) {
        dist[xx.first] = tmp;
        par[xx.first] = top;
        pq.push(xx.first);
      }
    }
  }
}
int main() {
  int u, v, wt;
  scanf("%d%d%d", &n, &m, &s);
  ;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &wt);
    ;
    adj[u].push_back({v, wt});
    adj[v].push_back({u, wt});
  }
  scanf("%d", &l);
  ;
  spath();
  int ans = 0;
  set<pair<int, pair<int, int>>> st;
  for (int i = 1; i <= n; i++) {
    if (dist[i] == l) ans++;
    int tmp = l - dist[i];
    for (auto xx : adj[i])
      if (par[i] != xx.first) {
        v = xx.first, wt = xx.second;
        if (tmp > 0 && tmp < wt && wt - tmp + dist[v] >= l) {
          if (i < v)
            st.insert({i, {v, tmp}});
          else
            st.insert({v, {i, wt - tmp}});
        }
      }
  }
  ans += st.size();
  cout << ans;
  return 0;
}
