#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10, maxm = 3e5 + 10;
inline long long rd() {
  long long x = 0;
  char c = getchar();
  int neg = 1;
  while (c < '0' || c > '9') {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * neg;
}
struct Edge {
  int a, b, l, ne;
} eg[maxm * 2];
int egh[maxn], ect;
int N, M, S;
int fa[maxn][20], bro[maxn], sh[maxn], dep[maxn];
int siz[maxn], ans, ine[maxn];
long long dis[maxn];
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    q;
queue<int> q2;
bool flag[maxn];
inline void adeg(int a, int b, int c) {
  eg[++ect].a = a;
  eg[ect].b = b;
  eg[ect].l = c;
  eg[ect].ne = egh[a];
  egh[a] = ect;
}
inline void dijkstra() {
  memset(dis, 127, sizeof(dis));
  dis[S] = 0;
  q.push(make_pair(0, S));
  while (!q.empty()) {
    int p = q.top().second;
    q.pop();
    if (flag[p]) continue;
    flag[p] = 1;
    for (int i = egh[p]; i; i = eg[i].ne) {
      int b = eg[i].b;
      if (dis[b] > dis[p] + eg[i].l) {
        dis[b] = dis[p] + eg[i].l;
        q.push(make_pair(dis[b], b));
      }
    }
  }
}
int getlca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = log2(dep[x] - dep[y]); i >= 0 && dep[x] != dep[y]; i--) {
    if (fa[x][i] && dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  }
  if (x == y) return x;
  for (int i = log2(dep[x]); i >= 0; i--) {
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  }
  return fa[x][0];
}
void dfs(int x) {
  siz[x] = 1;
  for (int i = sh[x]; i; i = bro[i]) {
    dfs(i);
    siz[x] += siz[i];
  }
  if (x != S) ans = max(ans, siz[x]);
}
int main() {
  int i, j, k;
  N = rd(), M = rd();
  S = rd();
  for (i = 1; i <= M; i++) {
    int a = rd(), b = rd(), c = rd();
    adeg(a, b, c);
    adeg(b, a, c);
  }
  dijkstra();
  for (i = 1; i <= ect; i++) {
    int a = eg[i].a, b = eg[i].b;
    if (dis[a] + eg[i].l == dis[b]) {
      ine[b]++;
    }
  }
  q2.push(S);
  dep[S] = 1;
  while (!q2.empty()) {
    int p = q2.front();
    q2.pop();
    for (i = egh[p]; i; i = eg[i].ne) {
      int b = eg[i].b;
      if (eg[i].l + dis[p] == dis[b]) {
        fa[b][0] = fa[b][0] ? getlca(p, fa[b][0]) : p;
        ine[b]--;
        if (!ine[b]) {
          dep[b] = dep[fa[b][0]] + 1;
          for (j = 0; fa[b][j] && fa[fa[b][j]]; j++)
            fa[b][j + 1] = fa[fa[b][j]][j];
          q2.push(b);
        }
      }
    }
  }
  for (i = 1; i <= N; i++) {
    if (i == S || !fa[i][0]) continue;
    bro[i] = sh[fa[i][0]], sh[fa[i][0]] = i;
  }
  dfs(S);
  printf("%d\n", ans);
  return 0;
}
