#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
template <int N>
struct distra {
  int n;
  vector<pair<int, int>> adj[N];
  void init(int n) {
    this->n = n;
    for (int i = 0; i < (int)(n); i++) adj[i].clear();
  }
  void addEdge(int u, int v, int c) { adj[u].emplace_back(v, c); }
  long long int dist[N];
  void go(int s) {
    fill_n(dist, n, INF);
    dist[s] = 0;
    priority_queue<pair<long long int, int>> q;
    q.emplace(0, s);
    while (!q.empty()) {
      long long int d;
      int u;
      tie(d, u) = q.top();
      q.pop();
      d = -d;
      if (d > dist[u]) continue;
      for (auto vc : adj[u]) {
        int v, c;
        tie(v, c) = vc;
        long long int cand = dist[u] + c;
        if (cand < dist[v]) {
          dist[v] = cand;
          q.emplace(-dist[v], v);
        }
      }
    }
  }
};
const int N = 2e5 + 100;
int n, deg[N];
bool vis[N];
vector<int> adj[N];
distra<N> md;
int bfs(int s) {
  static int l, r, q[N];
  static int sz, touched[2 * N];
  l = r = sz = 0;
  q[r++] = s;
  while (l < r) {
    int u = q[l++];
    vis[u] = true;
    for (auto v : adj[u]) {
      deg[v]--;
      touched[sz++] = v;
      if (deg[v] == 0) q[r++] = v;
    }
  }
  for (int i = 0; i < (int)(sz); i++) deg[touched[i]]++;
  return r;
}
int main() {
  int m, s;
  scanf("%d %d %d", &n, &m, &s);
  s--;
  md.init(n);
  while (m--) {
    int u, v, c;
    scanf("%d %d %d", &u, &v, &c);
    u--;
    v--;
    md.addEdge(u, v, c);
    md.addEdge(v, u, c);
  }
  md.go(s);
  for (int u = 0; u < (int)(n); u++)
    if (md.dist[u] < INF)
      for (auto vc : md.adj[u]) {
        int v, c;
        tie(v, c) = vc;
        if (md.dist[v] == md.dist[u] + c) {
          adj[u].push_back(v);
          deg[v]++;
        }
      }
  vector<int> ord;
  for (int u = 0; u < (int)(n); u++)
    if (md.dist[u] != INF) ord.push_back(u);
  sort((ord).begin(), (ord).end(),
       [&](int i, int j) { return md.dist[i] < md.dist[j]; });
  int ans = 0;
  for (int u : ord)
    if (u != s && !vis[u]) ans = max(ans, bfs(u));
  printf("%d\n", ans);
  return 0;
}
