#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MAXN = 3e5 + 10;
const int MAXL = 20;
int n, m, s;
vector<vector<pair<int, int>>> g;
bool read() {
  if (scanf("%d%d%d", &n, &m, &s) < 3) {
    return 0;
  }
  --s;
  g.clear();
  g.resize(n);
  for (int i = 0; i < int(m); ++i) {
    int a, b, w;
    scanf("%d%d%d", &a, &b, &w);
    --a;
    --b;
    g[a].push_back(make_pair(b, w));
    g[b].push_back(make_pair(a, w));
  }
  return 1;
}
vector<long long> dij(const vector<vector<pair<int, int>>>& g, const int& s) {
  const int N = ((int)(g).size());
  vector<long long> dist(N, INF);
  dist[s] = 0;
  set<pair<long long, int>> S;
  S.insert(make_pair(dist[s], s));
  while (!S.empty()) {
    int v = S.begin()->second;
    S.erase(S.begin());
    for (const auto& e : g[v]) {
      int to, w;
      tie(to, w) = e;
      if (dist[to] > dist[v] + w) {
        S.erase(make_pair(dist[to], to));
        dist[to] = dist[v] + w;
        S.insert(make_pair(dist[to], to));
      }
    }
  }
  return dist;
}
vector<vector<int>> dag;
vector<vector<int>> dag_t;
bool was[MAXN];
int par[MAXN][MAXL];
int depth[MAXN];
void dfs(int v, vector<int>& top) {
  assert(!was[v]);
  was[v] = 1;
  for (const auto& to : dag[v]) {
    if (!was[to]) {
      dfs(to, top);
    }
  }
  top.push_back(v);
}
int go_up(int v, int cnt) {
  int v0 = v;
  int cnt0 = cnt;
  for (int l = int(MAXL) - 1; l >= 0; --l) {
    if ((1 << l) <= cnt) {
      v = par[v][l];
      cnt -= 1 << l;
    }
  }
  assert(depth[v0] - depth[v] == cnt0);
  return v;
}
int lca(int v, int u) {
  if (depth[v] < depth[u]) {
    swap(v, u);
  }
  v = go_up(v, depth[v] - depth[u]);
  if (v == u) {
    return v;
  }
  for (int l = int(MAXL) - 1; l >= 0; --l) {
    if (par[v][l] != par[u][l]) {
      v = par[v][l];
      u = par[u][l];
    }
  }
  return par[v][0];
}
int ans[MAXN];
vector<vector<int>> sons;
int sz[MAXN];
void dfs_sz(int v) {
  sz[v] = 1;
  for (int to : sons[v]) {
    dfs_sz(to);
    sz[v] += sz[to];
  }
}
int solve() {
  vector<long long> dist = dij(g, s);
  dag.clear();
  dag.resize(n);
  dag_t.clear();
  dag_t.resize(n);
  for (int v = 0; v < int(n); ++v)
    for (const auto& e : g[v]) {
      int to, w;
      tie(to, w) = e;
      if (dist[v] + w == dist[to]) {
        dag[v].push_back(to);
        dag_t[to].push_back(v);
      }
    }
  vector<int> top;
  memset(was, 0, sizeof was);
  dfs(s, top);
  reverse(begin(top), end(top));
  sons.clear();
  sons.resize(n);
  for (int i = 0; i < int(MAXL); ++i) par[s][i] = s;
  depth[s] = 0;
  for (int it = 1; it < ((int)(top).size()); ++it) {
    int v = top[it];
    int p = -1;
    for (int from : dag_t[v]) {
      if (p == -1) {
        p = from;
      } else {
        p = lca(p, from);
      }
    }
    assert(p != -1);
    sons[p].push_back(v);
    depth[v] = depth[p] + 1;
    par[v][0] = p;
    for (int i = 1; i < MAXL; ++i) {
      par[v][i] = par[par[v][i - 1]][i - 1];
    }
  }
  memset(sz, 0, sizeof sz);
  dfs_sz(s);
  int ans = 0;
  for (int v = 0; v < int(n); ++v) {
    if (v != s) {
      ans = max(ans, sz[v]);
    }
  }
  return ans;
}
int main() {
  while (read()) {
    printf("%d\n", solve());
  }
  return 0;
}
