#include <bits/stdc++.h>
using LL = long long;
const int kN = 200000 + 5;
const int kLog = 19;
const LL inf = 3e14;
std::vector<std::pair<int, int>> edges[kN];
int n, m, s;
LL dist[kN];
int plca[kLog][kN], depth[kN];
int sz[kN];
int get_lca(int a, int b) {
  if (depth[a] < depth[b]) std::swap(a, b);
  for (int i = 0; i < kLog; ++i)
    if (depth[a] - depth[b] >> i & 1) a = plca[i][a];
  if (a == b) return a;
  for (int i = kLog - 1; i >= 0; --i)
    if (plca[i][a] != plca[i][b]) a = plca[i][a], b = plca[i][b];
  return plca[0][a];
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  s--;
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--;
    v--;
    edges[u].emplace_back(w, v);
    edges[v].emplace_back(w, u);
  }
  std::priority_queue<std::pair<LL, int>> pq;
  std::fill(dist, dist + n, inf);
  dist[s] = 0;
  pq.emplace(0, s);
  std::vector<int> order;
  while (!pq.empty()) {
    LL tmp;
    int u;
    std::tie(tmp, u) = pq.top();
    pq.pop();
    if (-tmp != dist[u]) continue;
    order.emplace_back(u);
    int lca = -1;
    for (auto e : edges[u]) {
      if (dist[e.second] > dist[u] + e.first) {
        dist[e.second] = dist[u] + e.first;
        pq.emplace(-dist[e.second], e.second);
      } else if (dist[e.second] + e.first == dist[u]) {
        if (lca == -1)
          lca = e.second;
        else
          lca = get_lca(lca, e.second);
      }
    }
    plca[0][u] = lca;
    depth[u] = lca == -1 ? 0 : depth[lca] + 1;
    for (int i = 1; i < kLog; ++i)
      plca[i][u] = plca[i - 1][u] == -1 ? -1 : plca[i - 1][plca[i - 1][u]];
  }
  int result = 0;
  std::fill(sz, sz + n, 1);
  for (int i = (int)order.size() - 1; i > 0; --i) {
    int u = order[i];
    sz[plca[0][u]] += sz[u];
    result = std::max(result, sz[u]);
  }
  printf("%d\n", result);
}
