#include <bits/stdc++.h>
int MAX_DIST = 200000000;
struct node_s {
  int id;
  int dist;
  bool visited;
};
struct edge_s {
  int length;
  bool visited;
};
struct edge_lst {
  int node;
  edge_s* edge;
  edge_lst* nxt;
};
bool compare_nodes(node_s* n1, node_s* n2) {
  if (n1->dist == n2->dist)
    return n1->id < n2->id;
  else
    return n1->dist < n2->dist;
}
int main(int argc, char* argv[]) {
  int n, m, s, L;
  std::cin >> n >> m >> s;
  s--;
  node_s* nodes = new node_s[n];
  edge_lst** lst = new edge_lst*[n];
  for (int i = 0; i < n; i++) {
    nodes[i].id = i;
    nodes[i].dist = MAX_DIST;
    nodes[i].visited = false;
    lst[i] = NULL;
  }
  for (int i = 0; i < m; i++) {
    int v, u, w;
    std::cin >> v >> u >> w;
    v--;
    u--;
    edge_s* edge = new edge_s;
    edge->length = w;
    edge->visited = false;
    edge_lst* ed_l = new edge_lst;
    ed_l->node = v;
    ed_l->edge = edge;
    ed_l->nxt = lst[u];
    lst[u] = ed_l;
    ed_l = new edge_lst;
    ed_l->node = u;
    ed_l->edge = edge;
    ed_l->nxt = lst[v];
    lst[v] = ed_l;
  }
  std::cin >> L;
  nodes[s].dist = 0;
  std::set<node_s*, bool (*)(node_s*, node_s*)> que(&compare_nodes);
  for (int i = 0; i < n; i++) que.insert(&nodes[i]);
  int num_vis = 0;
  while (!que.empty()) {
    node_s* nod = *que.begin();
    que.erase(que.begin());
    nod->visited = true;
    num_vis++;
    edge_lst* ed_l = lst[nod->id];
    while (ed_l != NULL) {
      if (!nodes[ed_l->node].visited) {
        int d = nod->dist + ed_l->edge->length;
        if (nodes[ed_l->node].dist > d) {
          que.erase(&nodes[ed_l->node]);
          nodes[ed_l->node].dist = d;
          que.insert(&nodes[ed_l->node]);
        }
      }
      ed_l = ed_l->nxt;
    }
  }
  int num_shafts = 0;
  for (int i = 0; i < n; i++)
    if (nodes[i].dist == L) num_shafts++;
  for (int i = 0; i < n; i++) {
    edge_lst* ed_l = lst[i];
    while (ed_l != NULL) {
      if (!ed_l->edge->visited) {
        int ed_len = ed_l->edge->length;
        ed_l->edge->visited = true;
        int from = L - nodes[i].dist;
        int to = ed_len - (L - nodes[ed_l->node].dist);
        if (from > 0 && to < ed_len) {
          if (from < to) num_shafts += 2;
          if (from == to) num_shafts++;
        }
        if ((from > 0 && from < ed_len && to >= ed_len) ||
            (from <= 0 && to > 0 && to < ed_len))
          num_shafts++;
      }
      ed_l = ed_l->nxt;
    }
  }
  std::cout << num_shafts;
  delete[] nodes;
  return 0;
}
