#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int INF = 1e9;
int n, m, c, l, ans;
set<pair<int, pair<int, int> > > s;
vector<pair<int, int> > nei[maxn];
vector<pair<int, pair<int, int> > > edge;
int dis[maxn];
bool mark[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> c;
  for (int i = 0; i < m; i++) {
    int v, u, w;
    cin >> v >> u >> w;
    nei[v].push_back(make_pair(w, u));
    nei[u].push_back(make_pair(w, v));
    edge.push_back(make_pair(w, make_pair(u, v)));
  }
  cin >> l;
  fill(dis, dis + maxn, INF);
  dis[c] = 0;
  mark[c] = true;
  for (int i = 0; i < nei[c].size(); i++) {
    int w = nei[c][i].first;
    int u = nei[c][i].second;
    s.insert(make_pair(w, make_pair(u, c)));
  }
  while (!s.empty()) {
    pair<int, pair<int, int> > a = *s.begin();
    int w = a.first;
    int u = a.second.first;
    int v = a.second.second;
    s.erase(s.begin());
    dis[u] = min(dis[u], w);
    mark[u] = true;
    for (int i = 0; i < nei[u].size(); i++) {
      int x = nei[u][i].second;
      int y = nei[u][i].first;
      if (!mark[x]) {
        s.insert(make_pair(dis[u] + y, make_pair(x, u)));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dis[i] == l) {
      ans++;
    }
  }
  for (int i = 0; i < edge.size(); i++) {
    int u = edge[i].second.second;
    int v = edge[i].second.first;
    int w = edge[i].first;
    if ((dis[v] > l && dis[u] < l) || (dis[v] < l && dis[u] > l)) {
      ans++;
    }
    if (dis[v] < l && dis[u] < l) {
      if (dis[v] + dis[u] + w - l > l) {
        ans += 2;
      }
      if (dis[v] + dis[u] + w - l == l) {
        ans++;
      }
    }
    if (dis[v] == l && dis[u] < l && dis[u] + w != dis[v]) {
      ans++;
    }
    if (dis[u] == l && dis[v] < l && dis[v] + w != dis[u]) {
      ans++;
    }
  }
  cout << ans;
}
