#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 50;
int n, m, S, ver[N * 2], edge[N * 2], nxt[N * 2], head[N], tot, st[N], tp,
    du[N], dep[N], f[N][20], l[N], dd[N], sz[N];
long long dis[N];
bool vis[N];
void add(int x, int y, int z) {
  ver[++tot] = y;
  edge[tot] = z;
  nxt[tot] = head[x];
  head[x] = tot;
}
struct node {
  int x;
  long long d;
  bool friend operator<(node a, node b) { return a.d > b.d; }
};
priority_queue<node> q;
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 18; ~i; i--)
    if (dep[f[x][i]] >= dep[y]) x = f[x][i];
  if (x == y) return x;
  for (int i = 18; ~i; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
int main() {
  scanf("%d%d%d", &n, &m, &S);
  for (int i = 1, x, y, z; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    add(x, y, z), add(y, x, z);
  }
  memset(dis, 0x3f, sizeof(dis));
  q.push((node){S, 0});
  dis[S] = 0;
  while (q.size()) {
    int x = q.top().x;
    q.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    for (int i = head[x], y; i; i = nxt[i])
      if (dis[y = ver[i]] > dis[x] + edge[i])
        dis[y] = dis[x] + edge[i], q.push((node){y, dis[y]});
  }
  for (int i = 1; i <= n; i++)
    for (int j = head[i]; j; j = nxt[j])
      if (dis[ver[j]] == dis[i] + edge[j]) du[ver[j]]++;
  st[tp = 1] = S;
  while (tp) {
    int x = st[tp--];
    dep[x] = dep[l[x]] + 1;
    f[x][0] = l[x];
    dd[l[x]]++;
    for (int i = 0; i < 18; i++) f[x][i + 1] = f[f[x][i]][i];
    for (int i = head[x], y; i; i = nxt[i])
      if (dis[y = ver[i]] == dis[x] + edge[i]) {
        if (!--du[y]) st[++tp] = y;
        l[y] = l[y] ? lca(l[y], x) : x;
      }
  }
  for (int i = 1; i <= n; i++)
    if (dep[i] && !dd[i]) st[++tp] = i;
  while (tp) {
    int x = st[tp--], y = f[x][0];
    sz[x]++;
    if (!--dd[y]) st[++tp] = y;
    sz[y] += sz[x];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (i != S) ans = max(ans, sz[i]);
  printf("%d\n", ans);
  return 0;
}
