#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, next, val;
} E[3][200010 << 2];
int head[3][200010], cnt[3];
int N, M, S, vis[200010], ans;
queue<int> q;
long long dis[200010];
int fa[200010], deg[200010], anc[200010][19], dep[200010], sz[200010];
void add(int m, int u, int v, int w) {
  E[m][++cnt[m]].to = v, E[m][cnt[m]].val = w, E[m][cnt[m]].next = head[m][u],
  head[m][u] = cnt[m];
}
void dfs(int u) {
  sz[u] = 1;
  for (int k = head[2][u]; k; k = E[2][k].next)
    dfs(E[2][k].to), sz[u] += sz[E[2][k].to];
  if (vis[u] && u && u != S) ans = max(ans, sz[u]);
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int dif = dep[u] - dep[v];
  for (int j = 18; j >= 0; --j)
    if (1 << j & dif) u = anc[u][j];
  if (u == v) return u;
  for (int j = 18; j >= 0; --j)
    if (anc[u][j] != anc[v][j]) u = anc[u][j], v = anc[v][j];
  return anc[u][0];
}
int main() {
  cin >> N >> M >> S;
  int u, v, w;
  for (int i = 1; i <= M; ++i)
    scanf("%d%d%d", &u, &v, &w), add(0, u, v, w), add(0, v, u, w);
  q.push(S);
  vis[S] = 1;
  fill(dis + 1, dis + N + 1, (1ll << 51)), dis[S] = 0;
  while (!q.empty()) {
    int n = q.front();
    q.pop();
    vis[n] = 0;
    for (int k = head[0][n]; k; k = E[0][k].next) {
      if (dis[E[0][k].to] > dis[n] + E[0][k].val) {
        dis[E[0][k].to] = dis[n] + E[0][k].val;
        if (!vis[E[0][k].to]) vis[E[0][k].to] = 1, q.push(E[0][k].to);
      }
    }
  }
  for (int i = 1; i <= N; ++i)
    for (int j = head[0][i]; j; j = E[0][j].next)
      if (dis[i] + E[0][j].val == dis[E[0][j].to])
        add(1, i, E[0][j].to, 0), deg[E[0][j].to]++;
  fill(vis, vis + N + 1, 0);
  for (int i = 1; i <= N; ++i) fa[i] = -1;
  q.push(S), fa[S] = 0;
  while (!q.empty()) {
    int n = q.front();
    q.pop(), vis[n] = 1, add(2, fa[n], n, 0);
    anc[n][0] = fa[n], dep[n] = dep[fa[n]] + 1;
    for (int i = 1; i <= 18; ++i) anc[n][i] = anc[anc[n][i - 1]][i - 1];
    for (int k = head[1][n]; k; k = E[1][k].next) {
      int ww = E[1][k].to;
      if (!(~fa[ww]))
        fa[ww] = n;
      else
        fa[ww] = lca(fa[ww], n);
      if (!--deg[ww]) q.push(ww);
    }
  }
  dfs(0);
  cout << ans << endl;
  return 0;
}
