#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
namespace ywy {
inline int get() {
  int n = 0;
  char c;
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9') break;
    if (c == '-') goto s;
  }
  n = c - '0';
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9')
      n = n * 10 + c - '0';
    else
      return (n);
  }
s:
  while ((c = getchar()) || 23333) {
    if (c >= '0' && c <= '9')
      n = n * 10 - c + '0';
    else
      return (n);
  }
}
int fa[200001], ance[200001][18], deep[200001];
namespace tree {
typedef struct _b {
  int dest;
  int nxt;
} bian;
bian memchi[1000001];
int gn = 1, heads[200001];
inline void add(int s, int t) {
  memchi[gn].dest = t;
  memchi[gn].nxt = heads[s];
  heads[s] = gn;
  gn++;
}
int size[200001];
void dfs(int pt) {
  size[pt] = 1;
  for (register int i = heads[pt]; i; i = memchi[i].nxt) {
    dfs(memchi[i].dest);
    size[pt] += size[memchi[i].dest];
  }
}
}  // namespace tree
inline int lca(int a, int b) {
  if (!(a && b)) return (a | b);
  if (deep[a] > deep[b]) swap(a, b);
  for (register int i = 17; i >= 0; i--) {
    if (deep[ance[b][i]] >= deep[a]) b = ance[b][i];
  }
  if (a == b) return (a);
  for (register int i = 17; i >= 0; i--) {
    if (ance[a][i] != ance[b][i]) a = ance[a][i], b = ance[b][i];
  }
  return (ance[a][0]);
}
typedef struct _b {
  int dest;
  int nxt;
  int len;
} bian;
bian memchi[1000001];
int gn = 1, heads[200001];
long long dis[200001];
unsigned char bv[200001];
inline void add(int s, int t, int l) {
  memchi[gn].dest = t;
  memchi[gn].len = l;
  memchi[gn].nxt = heads[s];
  heads[s] = gn;
  gn++;
}
typedef struct _n {
  int pt;
  long long dis;
  _n(int a, long long b) {
    pt = a;
    dis = b;
  }
  friend bool operator<(const _n &a, const _n &b) { return (a.dis > b.dis); }
} node;
priority_queue<node> que;
int deg[200001], Que[1000001];
void ywymain() {
  deep[0] = -1;
  int n = get(), m = get(), s = get();
  memset(dis, 0x7f, sizeof(dis));
  for (register int i = 1; i <= m; i++) {
    int s = get(), t = get(), l = get();
    add(s, t, l);
    add(t, s, l);
  }
  que.push(_n(s, 0));
  while (!que.empty()) {
    node cjr = que.top();
    que.pop();
    if (bv[cjr.pt]) continue;
    bv[cjr.pt] = 1;
    dis[cjr.pt] = cjr.dis;
    for (register int i = heads[cjr.pt]; i; i = memchi[i].nxt) {
      if (bv[memchi[i].dest]) continue;
      if (cjr.dis + memchi[i].len < dis[memchi[i].dest]) {
        que.push(
            _n(memchi[i].dest, dis[memchi[i].dest] = cjr.dis + memchi[i].len));
      }
    }
  }
  for (register int i = 1; i <= n; i++) {
    if (dis[i] == 0x7f7f7f7f7f7f7f7f) continue;
    for (register int j = heads[i]; j; j = memchi[j].nxt) {
      if (dis[i] + memchi[j].len == dis[memchi[j].dest]) deg[memchi[j].dest]++;
    }
  }
  int head = 0, tail = 1;
  Que[0] = s;
  do {
    int me = Que[head];
    head++;
    if (me != s) {
      int lst = 0;
      for (register int i = heads[me]; i; i = memchi[i].nxt) {
        if (dis[me] == dis[memchi[i].dest] + memchi[i].len)
          lst = lca(lst, memchi[i].dest);
      }
      ance[me][0] = lst;
      deep[me] = deep[lst] + 1;
      tree::add(lst, me);
      for (register int i = 1; i <= 17; i++)
        ance[me][i] = ance[ance[me][i - 1]][i - 1];
    }
    for (register int i = heads[me]; i; i = memchi[i].nxt) {
      if (dis[me] + memchi[i].len == dis[memchi[i].dest]) {
        deg[memchi[i].dest]--;
        if (!deg[memchi[i].dest]) Que[tail] = memchi[i].dest, tail++;
      }
    }
  } while (head < tail);
  tree::dfs(s);
  int mx = 0;
  for (register int i = 1; i <= n; i++) {
    if (i == s) continue;
    mx = max(mx, tree::size[i]);
  }
  cout << mx << endl;
}
}  // namespace ywy
int main() {
  ywy::ywymain();
  return (0);
}
