#include <bits/stdc++.h>
namespace IO {
const int maxn(1 << 21 | 1);
char ibuf[maxn], *iS, *iT, obuf[maxn], *oS = obuf, *oT = obuf + maxn - 1, _c,
                                       _st[55];
int _f, tp;
char Getc() {
  return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, maxn, stdin),
                      (iS == iT ? EOF : *iS++))
                   : *iS++);
}
void Flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
void Putc(char x) {
  *oS++ = x;
  if (oS == oT) Flush();
}
template <class Int>
void Input(Int &x) {
  for (_f = 0, _c = Getc(); _c < '0' || _c > '9'; _c = Getc()) _f = _c == '-';
  for (x = 0; _c <= '9' && _c >= '0'; _c = Getc())
    x = (x << 3) + (x << 1) + (_c ^ 48);
  if (_f) x = -x;
}
}  // namespace IO
using IO::Input;
using namespace std;
const int _ = 6e5 + 5;
int a[_], to[_], nex[_], w[_], n, m, S, p[_];
long long dis[_];
int f[_], g[_], deg[_], dep[_], st[_][19];
vector<int> e[_];
stack<int> s;
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
               greater<pair<long long, long long> > >
    q;
int lca(int x, int y) {
  if (!x || !y) return x + y;
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 18; ~i; --i)
    if (dep[st[x][i]] >= dep[y]) x = st[x][i];
  if (x == y) return x;
  for (int i = 18; ~i; --i)
    if (st[x][i] != st[y][i]) x = st[x][i], y = st[y][i];
  return st[x][0];
}
void solve() {
  q.push(pair<long long, long long>(0, S));
  dis[S] = 0;
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (p[u]) continue;
    for (int i = a[u]; i; i = nex[i]) {
      int v = to[i];
      if (dis[v] > dis[u] + w[i]) {
        dis[v] = dis[u] + w[i];
        q.push(pair<long long, long long>(dis[v], v));
      }
    }
  }
  for (int u = 1; u <= n; ++u)
    for (int i = a[u]; i; i = nex[i]) {
      int v = to[i];
      if (dis[v] == dis[u] + w[i]) e[u].push_back(v), ++deg[v];
    }
  s.push(S);
  int ans = 0;
  while (!s.empty()) {
    int u = s.top();
    s.pop();
    dep[u] = dep[st[u][0]] + 1;
    if (st[u][0] == S)
      g[u] = u, ans = max(ans, f[u] = 1);
    else
      g[u] = g[st[u][0]], ans = max(ans, ++f[g[u]]);
    for (int i = 1; i <= 18; ++i) st[u][i] = st[st[u][i - 1]][i - 1];
    for (int v : e[u]) {
      st[v][0] = lca(st[v][0], u);
      if (!--deg[v]) s.push(v);
    }
  }
  cout << ans << endl;
}
int main() {
  Input(n);
  Input(m);
  Input(S);
  for (int i = 1, t = 0; i <= m; ++i) {
    int u, v, W;
    Input(u);
    Input(v);
    Input(W);
    nex[++t] = a[u];
    to[t] = v;
    w[t] = W;
    a[u] = t;
    nex[++t] = a[v];
    to[t] = u;
    w[t] = W;
    a[v] = t;
  }
  if (a[S] == 0) cout << 0 << endl, exit(0);
  memset(dis, 127, sizeof(dis));
  solve();
  return 0;
}
