#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> graf;
vector<int> r;
struct S {
  int v1, v2, s;
  S(){};
  S(int V1, int V2, int S) {
    v1 = V1;
    v2 = V2;
    s = S;
  }
};
void deicstra(int v1) {
  r[v1] = 0;
  set<pair<int, int>> d;
  d.insert({0, v1});
  while (d.size() > 0) {
    int v = (*d.begin()).second;
    d.erase(d.begin());
    for (int i = 0; i < graf[v].size(); i++) {
      if (graf[v][i].second + r[v] < r[graf[v][i].first]) {
        d.erase({r[graf[v][i].first], graf[v][i].first});
        r[graf[v][i].first] = graf[v][i].second + r[v];
        d.insert({r[graf[v][i].first], graf[v][i].first});
      }
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, s;
  cin >> n >> m >> s;
  s--;
  graf.resize(n);
  r.resize(n, 1 << 30);
  vector<S> p(m);
  for (int i = 0; i < m; i++) {
    int v1, v2, d;
    cin >> v1 >> v2 >> d;
    v1--;
    v2--;
    graf[v1].push_back({v2, d});
    graf[v2].push_back({v1, d});
    p[i] = {v1, v2, d};
  }
  int l;
  cin >> l;
  deicstra(s);
  int out = 0;
  for (int i = 0; i < m; i++) {
    if (r[p[i].v1] + r[p[i].v2] + p[i].s == 2 * l) {
      if (r[p[i].v1] < l && r[p[i].v2] < l) out++;
    }
    if (r[p[i].v1] + r[p[i].v2] + p[i].s > 2 * l) {
      if (r[p[i].v1] < l && r[p[i].v1] + p[i].s > l) out++;
      if (r[p[i].v2] < l && r[p[i].v2] + p[i].s > l) out++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (r[i] == l) out++;
  }
  cout << out;
  return 0;
}
