#include <bits/stdc++.h>
using namespace std;
int a[200005], b[600005], c[600005], d[600005], f[200005][19], g[200005],
    h[200005], m, n, o[600005 >> 1], q[200005], s, t, x;
long long e[600005], p[600005 >> 1];
inline void put(int x, long long y) {
  int u = ++t;
  o[u] = x, p[u] = y;
  while (u > 1 && p[u] < p[u >> 1])
    swap(o[u], o[u >> 1]), swap(p[u], p[u >> 1]), u >>= 1;
}
inline void del() {
  int u = 1, v = 2;
  o[1] = o[t], p[1] = p[t--];
  while (v <= t) {
    if (v < t && p[v | 1] < p[v]) v++;
    if (p[u] <= p[v]) return;
    swap(o[u], o[v]), swap(p[u], p[v]), u = v, v = u << 1;
  }
}
inline int lca(int u, int v) {
  if (h[u] < h[v]) swap(u, v);
  for (int i = 0; h[u] - h[v]; i++)
    if (h[u] - h[v] & 1 << i) u = f[u][i];
  if (u == v) return u;
  for (int i = 17; i >= 0; i--)
    if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
  return *f[u];
}
int main() {
  scanf("%d%d%d", &n, &m, &s), memset(e, 0x7f, sizeof e), put(s, e[s] = 0),
      s = -1;
  for (int i = 1, u, v, w; i <= m; i++)
    scanf("%d%d%d", &u, &v, &w), b[++t] = a[u], c[a[u] = t] = v, d[t] = w,
                                 b[++t] = a[v], c[a[v] = t] = u, d[t] = w;
  t = 1;
  while (true) {
    while (t && p[1] != e[o[1]]) del();
    if (!t) break;
    int u = o[1];
    del();
    q[++s] = u;
    for (int i = a[u]; i; i = b[i])
      if (e[u] + d[i] < e[c[i]])
        put(c[i], e[c[i]] = e[u] + d[i]);
      else if (e[c[i]] + d[i] == e[u])
        *f[u] = *f[u] ? lca(*f[u], c[i]) : c[i];
    for (int i = 1; f[u][i - 1]; i++) f[u][i] = f[f[u][i - 1]][i - 1];
    h[u] = h[*f[u]] + 1;
  }
  while (s) x = max(x, ++g[q[s]]), g[*f[q[s]]] += g[q[s]], s--;
  printf("%d", x);
  return 0;
}
