#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 201000;
std::vector<pair<int, int> > e[N];
long long dis[N];
int vis[N];
set<pair<long long, int> > hs;
int ord[N], sz[N], dep[N];
const long long inf = 1ll << 60;
void dijkstra(int S, int n) {
  for (int i = 1; i < n + 1; i++) dis[i] = inf, vis[i] = 0;
  dis[S] = 0;
  for (int i = 1; i < n + 1; i++) hs.insert(make_pair(dis[i], i));
  for (int i = 0; i < n; i++) {
    int u = hs.begin()->second;
    hs.erase(hs.begin());
    vis[u] = 1;
    ord[i] = u;
    for (int j = 0; j < ((int)(e[u]).size()); j++) {
      int v = e[u][j].first;
      if (dis[v] > dis[u] + e[u][j].second) {
        hs.erase(make_pair(dis[v], v));
        dis[v] = dis[u] + e[u][j].second;
        hs.insert(make_pair(dis[v], v));
      }
    }
  }
}
int n, m, s, u, v, w, p[N][22];
int lca(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  for (int i = 20 - 1; i >= 0; i--)
    if (dep[p[v][i]] >= dep[u]) v = p[v][i];
  if (u == v) return u;
  for (int i = 20 - 1; i >= 0; i--)
    if (p[v][i] != p[u][i]) u = p[u][i], v = p[v][i];
  return p[u][0];
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    e[u].push_back(make_pair(v, w));
    e[v].push_back(make_pair(u, w));
  }
  dijkstra(s, n);
  p[s][0] = 0;
  dep[s] = 1;
  for (int i = 1; i < n; i++) {
    int d = -1;
    u = ord[i];
    for (auto p : e[u]) {
      if (dis[p.first] + p.second == dis[u]) {
        if (d == -1)
          d = p.first;
        else
          d = lca(d, p.first);
      }
    }
    if (dis[u] > (1ll << 50)) assert(d == -1);
    p[u][0] = d;
    dep[u] = dep[d] + 1;
    for (int j = 1; j < 21; j++) p[u][j] = p[p[u][j - 1]][j - 1];
  }
  for (int i = 1; i < n + 1; i++) sz[i] = 1;
  int ret = 0;
  for (int i = n - 1; i >= 1; i--) {
    u = ord[i];
    sz[p[u][0]] += sz[u];
    if (dis[u] <= (1ll << 50)) ret = max(ret, sz[u]);
  }
  printf("%d\n", ret);
}
