#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 100;
const int N = 1e6 + 100;
const long long int INF = 1e18;
const long long int mod = 1e9 + 9;
const long long int hash = 311;
int dis[MAXN];
int n;
vector<pair<int, int> > v[MAXN];
bool mark[MAXN];
int a[MAXN];
int b[MAXN];
int c[MAXN];
void DIJ(int x) {
  set<pair<int, int> > s;
  memset(dis, mod, sizeof dis);
  dis[x] = 0;
  for (int i = 1; i <= n; i++) s.insert({dis[i], i});
  while (!s.empty()) {
    pair<int, int> p = *(s.begin());
    int y = p.first;
    x = p.second;
    s.erase(s.begin());
    mark[x] = true;
    for (auto i : v[x]) {
      if (mark[i.first]) continue;
      s.erase({dis[i.first], i.first});
      dis[i.first] = min(dis[i.first], i.second + y);
      s.insert({dis[i.first], i.first});
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int m, k;
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    a[i] = x;
    b[i] = y;
    c[i] = z;
    v[x].push_back({y, z});
    v[y].push_back({x, z});
  }
  int s;
  cin >> s;
  DIJ(k);
  int cnt = 0;
  for (int i = 1; i <= n; i++)
    if (s == dis[i]) cnt++;
  for (int i = 0; i < m; i++) {
    int x = a[i];
    int y = b[i];
    int z = c[i];
    if (dis[x] > dis[y]) swap(x, y);
    if (dis[x] + z == dis[y]) {
      if (dis[x] < s && dis[y] > s) cnt++;
    } else {
      double d = dis[y] - dis[x];
      d += (double)((double)z - d) / 2;
      d += (double)dis[x];
      if (d == s)
        cnt++;
      else {
        if (dis[x] < s && d > s) cnt++;
        if (dis[y] < s && d > s) cnt++;
      }
    }
  }
  cout << cnt << "\n";
}
