#include <bits/stdc++.h>
using namespace std;
void file() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
int dx[] = {-1, 0, 0, 1, 1, 1, -1, -1};
int dy[] = {0, 1, -1, 0, 1, -1, 1, -1};
int main() {
  file();
  fast();
  int n, m, s;
  cin >> n >> m >> s;
  s--;
  vector<vector<pair<int, int>>> adj(n);
  vector<vector<int>> edgs(m);
  while (m--) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    edgs[m] = {u, v, w};
    adj[u].push_back({w, v});
    adj[v].push_back({w, u});
  }
  int l;
  cin >> l;
  vector<int> len(n, 1e9 + 5);
  priority_queue<pair<int, int>> q;
  q.push({0, s});
  len[s] = 0;
  int sum = 0;
  while (q.size()) {
    auto cur = q.top();
    q.pop();
    if (len[cur.second] < -1 * cur.first) continue;
    for (auto i : adj[cur.second]) {
      if (len[i.second] > -1 * cur.first + i.first) {
        len[i.second] = -1 * cur.first + i.first;
        q.push({-len[i.second], i.second});
      }
    }
  }
  for (auto i : edgs) {
    int u = i[0];
    int v = i[1];
    int w = i[2];
    set<pair<int, int>> st;
    if (len[u] < l && len[u] + w > l) {
      st.insert({l - len[u], w - (l - len[u])});
    }
    if (len[v] < l && len[v] + w > l) {
      st.insert({w - (l - len[v]), l - len[v]});
    }
    for (auto j : st) {
      int mn = min(len[u] + j.first, len[v] + j.second);
      if (mn == l) sum++;
    }
  }
  for (int i = 0; i < n; i++) sum += l == len[i];
  cout << sum;
}
