#include <bits/stdc++.h>
using namespace std;
void getre() {
  int x = 0;
  printf("%d\n", 1 / x);
}
void gettle() {
  int res = 1;
  while (1) res <<= 1;
  printf("%d\n", res);
}
template <typename T, typename S>
inline bool upmin(T &a, const S &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T, typename S>
inline bool upmax(T &a, const S &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename N, typename PN>
inline N flo(N a, PN b) {
  return a >= 0 ? a / b : -((-a - 1) / b) - 1;
}
template <typename N, typename PN>
inline N cei(N a, PN b) {
  return a > 0 ? (a - 1) / b + 1 : -(-a / b);
}
template <typename N>
N gcd(N a, N b) {
  return b ? gcd(b, a % b) : a;
}
template <typename N>
inline int sgn(N a) {
  return a > 0 ? 1 : (a < 0 ? -1 : 0);
}
inline void gn(long long &x) {
  int sg = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (sg = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= sg;
}
inline void gn(int &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(unsigned long long &x) {
  long long t;
  gn(t);
  x = t;
}
inline void gn(double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gn(long double &x) {
  double t;
  scanf("%lf", &t);
  x = t;
}
inline void gs(char *s) { scanf("%s", s); }
inline void gc(char &c) {
  while ((c = getchar()) > 126 || c < 33)
    ;
}
inline void pc(char c) { putchar(c); }
inline long long sqr(long long a) { return a * a; }
inline double sqrf(double a) { return a * a; }
const long long inf = 0x3f3f3f3f3f3f3f3fll;
const double pi = 3.14159265358979323846264338327950288L;
const double eps = 1e-6;
namespace tar {
int n;
bool recha[622222];
struct edge {
  int v, next;
} e[3660005];
int etot;
int g[622222], gt[622222], dom[622222];
inline void ae(int *g, int u, int v) {
  e[etot].v = v;
  e[etot].next = g[u];
  g[u] = etot++;
}
int dfn[622222], ind, id[622222];
int pre[622222], idom[622222], semi[622222];
int f[622222], best[622222];
int get(int x) {
  if (x == f[x]) return x;
  int y = get(f[x]);
  if (semi[best[x]] > semi[best[f[x]]]) best[x] = best[f[x]];
  return f[x] = y;
}
void dfs(int u) {
  id[dfn[u] = ++ind] = u;
  for (int i = g[u]; ~i; i = e[i].next)
    if (!dfn[e[i].v]) dfs(e[i].v), pre[dfn[e[i].v]] = dfn[u];
}
void tarjan() {
  for (int j = ind, u; u = id[j], j >= 2; j--) {
    for (int i = gt[u], v; v = dfn[e[i].v], ~i; i = e[i].next) {
      if (!v) continue;
      get(v);
      if (semi[best[v]] < semi[j]) semi[j] = semi[best[v]];
    }
    ae(dom, semi[j], j);
    int x = f[j] = pre[j];
    for (int i = dom[x], z; z = e[i].v, ~i; i = e[i].next) {
      get(z);
      if (semi[best[z]] < x)
        idom[z] = best[z];
      else
        idom[z] = x;
    }
    dom[x] = -1;
  }
  for (int i = 2; i <= ind; i++) {
    if (semi[i] != idom[i]) idom[i] = idom[idom[i]];
    ae(dom, idom[i], i);
  }
}
int ans[222222];
void calc(int u) {
  ans[u] = 1;
  for (int i = dom[dfn[u]]; ~i; i = e[i].next) {
    calc(id[e[i].v]);
    ans[u] += ans[id[e[i].v]];
  }
}
int work(int s) {
  for (int i = 1; i <= n; i++) {
    f[i] = best[i] = semi[i] = i;
  }
  dfs(s);
  tarjan();
  calc(s);
  int ma = 0;
  for (int i = (1), _ed = (n + 1); i < _ed; i++)
    if (i != s && recha[i]) upmax(ma, ans[i]);
  return ma;
}
};  // namespace tar
namespace dij {
struct edge {
  int v, next, w;
} e[666666];
int etot = 0;
int g[222222];
void ae(int u, int v, int w) {
  e[etot].v = v;
  e[etot].w = w;
  e[etot].next = g[u];
  g[u] = etot++;
}
long long dis[222222];
int n, s;
struct node {
  long long d;
  int v;
};
int operator<(const node &a, const node &b) { return a.d > b.d; }
priority_queue<node> qu;
void work() {
  memset((g), (-1), sizeof(g));
  gn(n);
  int m;
  gn(m);
  gn(s);
  while (m--) {
    int u, v, w;
    gn(u);
    gn(v);
    gn(w);
    ae(u, v, w);
    ae(v, u, w);
  }
  memset((dis), (63), sizeof(dis));
  dis[s] = 0;
  qu.push((node){0, s});
  while (!qu.empty()) {
    node x = qu.top();
    qu.pop();
    int u = x.v;
    if (dis[u] != x.d) continue;
    for (int i = g[u]; ~i; i = e[i].next)
      if (upmin(dis[e[i].v], dis[u] + e[i].w)) {
        qu.push((node){dis[e[i].v], e[i].v});
      }
  }
  memset((tar::g), (-1), sizeof(tar::g));
  memset((tar::gt), (-1), sizeof(tar::gt));
  memset((tar::dom), (-1), sizeof(tar::dom));
  for (int u = (1), _ed = (n + 1); u < _ed; u++)
    if (dis[u] < inf) {
      tar::recha[u] = 1;
      for (int i = g[u]; ~i; i = e[i].next)
        if (dis[u] + e[i].w == dis[e[i].v]) {
          tar::ae(tar::g, u, e[i].v);
          tar::ae(tar::gt, e[i].v, u);
        }
    }
  tar::n = n;
  printf("%d\n", tar::work(s));
}
};  // namespace dij
int main() {
  dij::work();
  return 0;
}
