#include <bits/stdc++.h>
using namespace std;
namespace Graph {
struct Node;
struct Edge {
  Node *l, *r;
  int w;
  Node* from(Node* pos) {
    if (pos == l) return r;
    return l;
  }
};
struct Node {
  int index;
  long long dist = -1;
  int inDegree = 0;
  vector<Edge*> conn;
};
struct Graph {
  vector<Node> node;
  vector<Edge> edge;
  int n;
  Graph(int nsize) {
    n = nsize;
    node.resize(n);
    for (int i = 0; i < n; i++) node[i].index = i;
  }
  void addEdge(int a, int b, int w) { edge.push_back({&node[a], &node[b], w}); }
  void initConn() {
    for (auto& ce : edge) {
      ce.l->conn.push_back(&ce);
      ce.r->conn.push_back(&ce);
    }
  }
  void getDists(int s) {
    priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                   greater<pair<long long, int> > >
        front;
    front.push({0, s});
    vector<bool> explr(n, false);
    while (front.size() > 0) {
      long long dist;
      int pos;
      tie(dist, pos) = front.top();
      front.pop();
      if (explr[pos]) continue;
      explr[pos] = true;
      for (auto e : node[pos].conn)
        front.push({dist + e->w, e->from(&node[pos])->index});
      node[pos].dist = dist;
    }
    for (auto& ce : edge) {
      if (ce.r->dist - ce.l->dist == ce.w) ce.r->inDegree++;
      if (ce.l->dist - ce.r->dist == ce.w) ce.l->inDegree++;
    }
  }
  int solve(int pos) {
    static vector<bool> explr = vector<bool>(n, false);
    if (explr[pos]) return 0;
    vector<Node*> front(1, &node[pos]);
    int result = 0;
    for (int ind = 0; ind < (int)front.size(); ind++) {
      Node* cur = front[ind];
      explr[cur->index] = true;
      result++;
      for (auto ep : cur->conn) {
        Node* next = ep->from(cur);
        if (next->dist - cur->dist == ep->w) {
          next->inDegree--;
          if (next->inDegree == 0) front.push_back(next);
        }
      }
    }
    for (Node* cur : front)
      for (auto ep : cur->conn)
        if (ep->from(cur)->dist - cur->dist == ep->w) ep->from(cur)->inDegree++;
    return result;
  }
};
};  // namespace Graph
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m, s;
  cin >> n >> m >> s;
  s--;
  Graph::Graph g(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g.addEdge(u - 1, v - 1, w);
  }
  g.initConn();
  g.getDists(s);
  int result = 0;
  vector<pair<long long, int> > byDist;
  for (int i = 0; i < n; i++)
    if (g.node[i].dist != -1 && i != s) byDist.push_back({g.node[i].dist, i});
  sort(byDist.begin(), byDist.end());
  for (auto cp : byDist) result = max(result, g.solve(cp.second));
  cout << result << '\n';
  return 0;
}
