#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
const int oo = 1e9;
const int mod = 1e5;
vector<pair<int, int>> g[N];
int n, m, s, l, ans;
long long bf[N], cost[N];
bool vis[N];
void dij() {
  priority_queue<pair<int, int>> q;
  q.push({1, s});
  for (int i = 1; i <= n; i++) cost[i] = 1e18;
  cost[s] = 0;
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = 0; i < g[u].size(); ++i) {
      int v = g[u][i].first;
      int nc = cost[u] + g[u][i].second;
      if (!vis[v] && cost[v] > nc) {
        cost[v] = nc;
        bf[v] = u;
        q.push({-nc, v});
      }
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    g[u].push_back({v, w});
    swap(u, v);
    g[u].push_back({v, w});
  }
  scanf("%d", &l);
  dij();
  for (int u = 1; u <= n; u++) {
    ans += (cost[u] == l);
    for (int j = 0; j < g[u].size(); j++) {
      int v = g[u][j].first;
      int cst = g[u][j].second;
      if (u > v) continue;
      int cur = l - cost[u];
      set<int> p;
      if (cur < cst && cur > 0 && cost[v] + cst - cur >= l) p.insert(cur);
      cur = l - cost[v];
      if (cur < cst && cur > 0 && cost[u] + cst - cur >= l)
        p.insert(g[u][j].second - cur);
      ans += p.size();
    }
  }
  printf("%d\n", ans);
}
