#include <bits/stdc++.h>
using namespace std;
inline int readInt() {
  static int n, ch;
  n = 0, ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
  return n;
}
const int MAX_N = 200000 + 3, MAX_M = 300000 + 3;
struct edge {
  edge *next;
  int to, cost;
  edge(edge *next = NULL, int to = 0, int cost = 0)
      : next(next), to(to), cost(cost) {}
} pool[MAX_M * 2 + MAX_N], *pit = pool, *first[MAX_N], *newFirst[MAX_N];
int n, m, s;
long long dis[MAX_N];
inline bool tension(long long &a, const long long &b) {
  return b < a ? a = b, true : false;
}
void spfa(int s) {
  static int q[MAX_N];
  static bool inQ[MAX_N];
  int l = 0, r = 0;
  memset(dis, 0x3f, sizeof dis);
  dis[s] = 0, q[r++] = s;
  while (r - l >= 1) {
    int u = q[(l++) % n];
    inQ[u] = false;
    for (edge *e = first[u]; e; e = e->next)
      if (tension(dis[e->to], dis[u] + e->cost) && !inQ[e->to])
        inQ[e->to] = true, q[(r++) % n] = e->to;
  }
}
inline bool cmp(const int &i, const int &j) { return dis[i] < dis[j]; }
int logs[MAX_N];
int fa[MAX_N], anc[20][MAX_N], dep[MAX_N];
inline int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int bit = logs[dep[u]]; bit >= 0; --bit)
    if (dep[u] - (1 << bit) >= dep[v]) u = anc[bit][u];
  if (u == v) return u;
  for (int bit = logs[dep[u]]; bit >= 0; --bit)
    if (dep[u] - (1 << bit) >= 0 && anc[bit][u] != anc[bit][v])
      u = anc[bit][u], v = anc[bit][v];
  return fa[u];
}
int sz[MAX_N];
int dfs(int u) {
  sz[u] = 1;
  for (edge *e = newFirst[u]; e; e = e->next) sz[u] += dfs(e->to);
  return sz[u];
}
int solve() {
  static int ordID[MAX_N];
  for (int i = 0; i < n; ++i) ordID[i] = i;
  sort(ordID, ordID + n, cmp);
  for (int i = 2; i <= n; ++i) logs[i] = logs[i >> 1] + 1;
  dep[s] = 0, fa[s] = -1;
  for (int i = 0; i < n; ++i) {
    int u = ordID[i];
    fa[u] = -1;
    for (edge *e = first[u]; e; e = e->next)
      if (dis[e->to] + e->cost == dis[u]) {
        if (fa[u] == -1)
          fa[u] = e->to;
        else
          fa[u] = lca(fa[u], e->to);
      }
    if (fa[u] != -1) {
      dep[u] = dep[fa[u]] + 1;
      newFirst[fa[u]] = new (pit++) edge(newFirst[fa[u]], u);
      anc[0][u] = fa[u];
      for (int w = 1; (1 << w) <= dep[u]; ++w)
        anc[w][u] = anc[w - 1][anc[w - 1][u]];
    }
  }
  dfs(s);
  int ans = 0;
  for (int i = 0; i < n; ++i)
    if (i != s) ans = max(ans, sz[i]);
  return ans;
}
int main() {
  n = readInt(), m = readInt(), s = readInt() - 1;
  for (int i = 0; i < m; ++i) {
    int u = readInt() - 1, v = readInt() - 1, w = readInt();
    first[u] = new (pit++) edge(first[u], v, w);
    first[v] = new (pit++) edge(first[v], u, w);
  }
  spfa(s);
  printf("%d\n", solve());
  return 0;
}
