#include <bits/stdc++.h>
using namespace std;
const int INF = 2 * 1e9;
const double EPS = 1e-9;
const int MaxN = 100000 + 5;
const int MaxM = 2 * 100000 + 5;
int N, M, S, L, Dist[MaxN];
typedef struct Node {
  int idx;
  Node(void) {}
  Node(int _idx) { idx = _idx; }
  inline bool operator<(const Node &NewNode) const {
    return Dist[idx] > Dist[NewNode.idx];
  }
};
typedef struct Edge {
  int idx, Weight;
  Edge(void) {}
  Edge(int _idx, int _Weight) {
    idx = _idx;
    Weight = _Weight;
  }
};
vector<Edge> E[MaxM];
inline void Dijkstra(int Start) {
  for (int i = 0; i < N; i++) Dist[i] = INF;
  priority_queue<Node> PQ;
  PQ.push(Node(Start));
  Dist[Start] = 0;
  while (!PQ.empty()) {
    Node CurrNode = PQ.top();
    PQ.pop();
    for (vector<Edge>::iterator it = E[CurrNode.idx].begin();
         it != E[CurrNode.idx].end(); it++) {
      Node NextNode = Node((*it).idx);
      int Weight = (*it).Weight;
      if (Dist[CurrNode.idx] + Weight < Dist[NextNode.idx]) {
        Dist[NextNode.idx] = Dist[CurrNode.idx] + Weight;
        PQ.push(NextNode);
      }
    }
  }
}
vector<pair<pair<int, int>, int> > Edges;
int main(void) {
  scanf("%d %d %d", &N, &M, &S);
  S--;
  for (int i = 0; i < M; i++) {
    int idx, idy, Weight;
    scanf("%d %d %d", &idx, &idy, &Weight);
    idx--;
    idy--;
    E[idx].push_back(Edge(idy, Weight));
    E[idy].push_back(Edge(idx, Weight));
    Edges.push_back(make_pair(make_pair(idx, idy), Weight));
  }
  scanf("%d", &L);
  Dijkstra(S);
  int Sol = 0;
  for (int i = 0; i < N; i++)
    if (Dist[i] == L) Sol++;
  for (int i = 0; i < M; i++) {
    int idx = Edges[i].first.first, idy = Edges[i].first.second,
        Weight = Edges[i].second;
    int Pos1 = -1, Pos2 = -1;
    if ((Dist[idx] < L) && (L < Dist[idx] + Weight) &&
        (L <= Dist[idy] + Dist[idx] + Weight - L))
      Pos1 = L - Dist[idx];
    if ((Dist[idy] < L) && (L < Dist[idy] + Weight) &&
        (L <= Dist[idx] + Dist[idy] + Weight - L))
      Pos2 = Dist[idy] + Weight - L;
    if (Pos1 >= 0) Sol++;
    if ((Pos2 >= 0) && (Pos2 != Pos1)) Sol++;
  }
  printf("%d\n", Sol);
  return 0;
}
