#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 1, MOD = 1e9 + 7;
int n, m, root, l, dis[N], an;
vector<pair<int, int> > g[N];
bool vis[N];
void read() {
  scanf("%d%d%d", &n, &m, &root);
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  scanf("%d", &l);
}
void dijkstra() {
  for (int i = 1; i <= n; ++i) dis[i] = 1e9;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      q;
  q.push(make_pair(0, root));
  dis[root] = 0;
  vis[root] = 0;
  while (!q.empty()) {
    int current = q.top().second, cost = q.top().first;
    q.pop();
    if (cost > dis[current]) continue;
    for (int i = 0; i < g[current].size(); ++i) {
      int newnode = g[current][i].first, newcost = g[current][i].second;
      if (dis[newnode] > newcost + dis[current]) {
        dis[newnode] = dis[current] + newcost;
        q.push(make_pair(dis[newnode], newnode));
      }
    }
  }
}
void test() {
  for (int i = 1; i <= n; ++i) {
    cout << i << "  : " << dis[i] << "\n";
  }
}
int main() {
  read();
  dijkstra();
  for (int i = 1; i <= n; ++i) {
    if (dis[i] == l) ++an;
    for (int j = 0; j < g[i].size(); ++j) {
      set<int> st;
      int current = g[i][j].first, wight = g[i][j].second;
      if (current < i) {
        int rem = l - dis[i];
        if (rem < wight && rem > 0 && wight + dis[current] - rem >= l)
          st.insert(rem);
        rem = l - dis[current];
        if (rem < wight && rem > 0 && wight + dis[i] - rem >= l)
          st.insert(wight - rem);
        an += st.size();
      }
    }
  }
  printf("%d\n", an);
}
