#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const int N = (int)1e5 + 4;
const long double eps = 1e-12;
const int M = 3001;
const int inf = (int)1e9 + 7;
const long double pi = acos(-1.0);
vector<pair<int, int> > g[N];
set<pair<int, int> > q;
int d[N];
int main() {
  int n, m, s;
  scanf("%d %d %d", &n, &m, &s);
  --s;
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    --a;
    --b;
    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }
  int l;
  scanf("%d", &l);
  for (int i = 0; i < n; ++i)
    if (i != s) {
      d[i] = inf;
      q.insert(make_pair(d[i], i));
    }
  d[s] = 0;
  q.insert(make_pair(0, s));
  for (; (int)q.size() > 0;) {
    pair<int, int> t = *q.begin();
    q.erase(t);
    int v = t.second;
    for (int i = 0; i < (int)g[v].size(); ++i)
      if (d[g[v][i].first] > d[v] + g[v][i].second) {
        q.erase(make_pair(d[g[v][i].first], g[v][i].first));
        d[g[v][i].first] = d[v] + g[v][i].second;
        q.insert(make_pair(d[g[v][i].first], g[v][i].first));
      }
  }
  int ans = 0;
  int p = 0;
  for (int i = 0; i < n; ++i)
    if (d[i] == l) ++ans;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < (int)g[i].size(); ++j)
      for (int t = 1; t < g[i][j].second; ++t)
        if (l == (d[i] + t < d[g[i][j].first] + g[i][j].second - t
                      ? d[i] + t
                      : d[g[i][j].first] + g[i][j].second - t))
          ++p;
  p /= 2;
  ans += p;
  printf("%d", ans);
  return 0;
}
