#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 77, L = 19;
int n, m, Root, A, Par[N][L], h[N], Sz[N];
bool M[N];
long long d[N];
vector<pair<int, int> > a[N];
vector<int> b[N], f[N], ts;
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    Pq;
inline int GetPar(int v, int k) {
  for (int i = 0; i < L; ++i)
    if (k & (1 << i)) v = Par[v][i];
  return v;
}
inline int GetLca(int v, int u) {
  if (h[v] < h[u]) swap(v, u);
  v = GetPar(v, h[v] - h[u]);
  if (v == u) return v;
  for (int i = L - 1; i >= 0; --i)
    if (Par[v][i] != Par[u][i]) v = Par[v][i], u = Par[u][i];
  return Par[v][0];
}
void dfs(int v) {
  M[v] = 1;
  for (int u : b[v])
    if (!M[u]) dfs(u);
  ts.push_back(v);
}
int main() {
  memset(d, 63, sizeof(d));
  scanf("%d %d %d", &n, &m, &Root), d[Root] = 0;
  for (int v, u, w, i = 1; i <= m; ++i) {
    scanf("%d %d %d", &v, &u, &w);
    a[v].push_back(make_pair(u, w));
    a[u].push_back(make_pair(v, w));
  }
  Pq.push(make_pair(0ll, Root));
  while (!Pq.empty()) {
    int v = Pq.top().second;
    Pq.pop();
    if (M[v]) continue;
    M[v] = 1;
    for (auto x : a[v]) {
      int u = x.first, w = x.second;
      if (d[u] > d[v] + w) {
        d[u] = d[v] + w, f[u].clear();
        Pq.push(make_pair(d[u], u));
      }
      if (d[u] == d[v] + w) Par[u][0] = v, f[u].push_back(v);
    }
  }
  memset(M, 0, sizeof(M));
  for (int i = 1; i <= n; ++i) {
    for (int x : f[i]) b[x].push_back(i);
  }
  dfs(Root);
  reverse(ts.begin(), ts.end());
  for (int x : ts) {
    if (x == Root) continue;
    for (auto y : f[x]) Par[x][0] = GetLca(Par[x][0], y);
    h[x] = h[Par[x][0]] + 1;
    for (int i = 1; i < L; ++i) Par[x][i] = Par[Par[x][i - 1]][i - 1];
  }
  reverse(ts.begin(), ts.end());
  for (int x : ts) {
    if (x == Root) continue;
    ++Sz[x];
    Sz[Par[x][0]] += Sz[x];
    A = max(A, Sz[x]);
  }
  printf("%d\n", A);
  return 0;
}
