#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 5;
long long N, M, S, dis[maxn], in[maxn], top[maxn],
    lg2[maxn] = {-1}, dep[maxn], fa[maxn][20], size[maxn], ans;
vector<long long> G[maxn], W[maxn], G1[maxn], G2[maxn], G3[maxn];
void topsort() {
  long long cnt = 0;
  queue<long long> q;
  for (long long i = 1; i <= N; i++)
    if (!in[i] && dis[i] != 4557430888798830399ll) q.push(i);
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    top[++cnt] = u;
    for (long long i = 0; i < G1[u].size(); i++) {
      long long v = G1[u][i];
      --in[v];
      if (!in[v]) q.push(v);
    }
  }
}
long long LCA(long long u, long long v) {
  if (dep[u] < dep[v]) swap(u, v);
  while (dep[u] > dep[v]) u = fa[u][lg2[dep[u] - dep[v]]];
  if (u == v) return u;
  for (long long k = lg2[dep[u]]; k >= 0; k--)
    if (fa[u][k] != fa[v][k]) u = fa[u][k], v = fa[v][k];
  return fa[u][0];
}
void dfs(long long u) {
  size[u] = 1;
  for (long long i = 0; i < G3[u].size(); i++) {
    long long v = G3[u][i];
    dfs(v);
    size[u] += size[v];
  }
  if (u != N + 1 && u != S) ans = max(ans, size[u]);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M >> S;
  for (long long i = 1; i <= N; i++) lg2[i] = lg2[i >> 1] + 1;
  for (long long i = 1, u, v, w; i <= M; i++) {
    cin >> u >> v >> w;
    G[u].push_back(v);
    W[u].push_back(w);
    G[v].push_back(u);
    W[v].push_back(w);
  }
  memset(dis, 0x3f, sizeof(dis));
  queue<long long> q;
  q.push(S);
  dis[S] = 0;
  while (!q.empty()) {
    long long u = q.front();
    q.pop();
    for (long long i = 0; i < G[u].size(); i++) {
      long long v = G[u][i], w = W[u][i];
      if (dis[v] > dis[u] + w) dis[v] = dis[u] + w, q.push(v);
    }
  }
  for (long long u = 1; u <= N; u++)
    for (long long i = 0; i < G[u].size(); i++) {
      long long v = G[u][i], w = W[u][i];
      if (dis[v] == dis[u] + w) G1[u].push_back(v), ++in[v], G2[v].push_back(u);
    }
  topsort();
  for (long long i = 1; i <= N; i++) {
    if (!top[i]) break;
    long long u = top[i];
    if (!G2[u].size()) G2[u].push_back(N + 1);
    long long x = G2[u][0];
    for (long long j = 1; j < G2[u].size(); j++) {
      long long v = G2[u][j];
      x = LCA(x, v);
    }
    G3[x].push_back(u);
    dep[u] = dep[x] + 1;
    fa[u][0] = x;
    for (long long k = 1; k <= lg2[dep[u]]; k++)
      fa[u][k] = fa[fa[u][k - 1]][k - 1];
  }
  dfs(N + 1);
  cout << ans;
  return 0;
}
