#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3fll;
int n, idx, h[5000010], dfn[200010], pos[200010], sdom[200010], idom[200010],
    fa[200010], f[200010], mi[200010], sz[200010];
long long d[200010];
struct adlist1 {
  int u[200010], v[600010], w[600010], p[600010], m;
  void add(int x, int y, int z) {
    ++m;
    v[m] = y;
    w[m] = z;
    p[m] = u[x];
    u[x] = m;
  }
} g;
struct adlist2 {
  int u[200010], v[600010], p[600010], m;
  void add(int x, int y) {
    ++m;
    v[m] = y;
    p[m] = u[x];
    u[x] = m;
  }
} G, GR;
struct adlist3 {
  int u[200010], v[200010], p[200010], m;
  void add(int x, int y) {
    ++m;
    v[m] = y;
    p[m] = u[x];
    u[x] = m;
  }
} T, S;
bool cmp(int x, int y) { return d[x] > d[y]; }
void dijkstra(int s) {
  memset(d, 0x3f, sizeof(d));
  h[++h[0]] = s;
  d[s] = 0;
  while (h[0]) {
    pop_heap(h + 1, h + h[0] + 1, cmp);
    int x = h[h[0]--];
    for (int i = g.u[x]; i; i = g.p[i]) {
      int y = g.v[i], z = g.w[i];
      if (d[x] + z < d[y]) {
        d[y] = d[x] + z;
        h[++h[0]] = y;
        push_heap(h + 1, h + h[0] + 1, cmp);
      }
    }
  }
}
void makeDAG() {
  for (int x = 1; x <= n; ++x)
    for (int i = g.u[x]; i; i = g.p[i]) {
      int y = g.v[i], z = g.w[i];
      if (d[x] + z == d[y]) {
        G.add(x, y);
        GR.add(y, x);
      }
    }
}
void dfs(int x) {
  dfn[x] = ++idx;
  pos[idx] = x;
  sdom[x] = x;
  f[x] = x;
  mi[x] = x;
  for (int i = G.u[x]; i; i = G.p[i]) {
    int y = G.v[i];
    if (!dfn[y]) {
      fa[y] = x;
      dfs(y);
    }
  }
}
void compress(int x) {
  if (f[x] == f[f[x]]) return;
  int y = f[x];
  compress(y);
  if (dfn[sdom[mi[y]]] < dfn[sdom[mi[x]]]) mi[x] = mi[y];
  f[x] = f[y];
}
int find(int x) {
  if (f[x] != f[f[x]]) compress(x);
  return mi[x];
}
void dfs2(int x) {
  sz[x] = 1;
  for (int i = T.u[x]; i; i = T.p[i]) {
    int y = T.v[i];
    dfs2(y);
    sz[x] += sz[y];
  }
}
int main() {
  int m, s;
  scanf("%d%d%d", &n, &m, &s);
  while (m--) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    g.add(x, y, z);
    g.add(y, x, z);
  }
  dijkstra(s);
  makeDAG();
  dfs(s);
  for (int i = idx; i; --i) {
    int x = pos[i];
    for (int j = GR.u[x]; j; j = GR.p[j]) {
      int y = find(GR.v[j]);
      if (dfn[sdom[y]] < dfn[sdom[x]]) sdom[x] = sdom[y];
    }
    if (i > 1) S.add(sdom[x], x);
    for (int j = S.u[x]; j; j = S.p[j]) {
      int y = S.v[j], z = find(y);
      idom[y] = x == sdom[z] ? x : z;
    }
    if (i > 1) f[x] = fa[x];
  }
  for (int i = 2; i <= idx; ++i) {
    int x = pos[i];
    if (idom[x] != sdom[x]) idom[x] = idom[idom[x]];
    T.add(idom[x], x);
  }
  dfs2(s);
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    if (i != s) ans = max(ans, sz[i]);
  printf("%d\n", ans);
  return 0;
}
