#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, l, s;
vector<pair<int, int> > adj[N], edges;
vector<int> co;
long long d[N];
void Dijkstra() {
  priority_queue<pair<int, int> > q;
  q.push(pair<int, int>(0, s));
  for (int i = 1; i <= n; i++) d[i] = 1e16;
  d[s] = 0;
  while (q.size()) {
    long long cost = q.top().first * -1;
    int cur = q.top().second;
    q.pop();
    if (d[cur] < cost) continue;
    for (int i = 0; i < adj[cur].size(); i++) {
      int to = adj[cur][i].first;
      long long toCost = cost + adj[cur][i].second;
      if (toCost < d[to]) {
        d[to] = toCost;
        q.push(pair<int, int>(-toCost, to));
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  while (m--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    co.push_back(c);
    adj[a].push_back(pair<int, int>(b, c));
    adj[b].push_back(pair<int, int>(a, c));
    edges.push_back(pair<int, int>(a, b));
  }
  Dijkstra();
  cin >> l;
  int sum = 0;
  for (int i = 0; i < edges.size(); i++) {
    int a = edges[i].first, b = edges[i].second, c = co[i];
    if (d[a] > d[b]) swap(a, b);
    if (d[a] < l && d[a] + c > l) {
      if (d[b] < l) {
        int x = l - d[a];
        int y = l - d[b];
        if (x + y > c) continue;
        sum++;
        sum += (x + y < c);
      } else if (d[a] + c > l)
        sum++;
    }
  }
  for (int i = 1; i <= n; i++) sum += d[i] == l;
  cout << sum;
  return 0;
}
