#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
const long long lg = 23;
vector<pair<long long, long long> > graph[N];
long long n, m, st;
long long d[N];
long long h[N];
set<pair<long long, long long> > s;
vector<long long> tree[N];
vector<long long> vec;
long long par[N][lg];
long long sz[N];
long long ans = 0;
void djikstra(long long st) {
  memset(d, 127, sizeof d);
  d[st] = 0;
  s.insert({d[st], st});
  while (s.size()) {
    long long v = (*s.begin()).second;
    s.erase(s.begin());
    for (auto nei : graph[v]) {
      long long u = nei.first;
      long long w = nei.second;
      if (d[v] + w < d[u]) {
        s.erase({d[u], u});
        d[u] = d[v] + w;
        s.insert({d[u], u});
      }
    }
  }
}
bool cmp(long long v, long long u) { return d[v] < d[u]; }
long long lca(long long v, long long u) {
  if (v == -1) {
    return u;
  }
  if (h[v] > h[u]) {
    swap(u, v);
  }
  for (long long i = 0; i < lg; i++) {
    if (h[u] - h[v] >> i & 1) {
      u = par[u][i];
    }
  }
  for (long long i = lg - 1; i >= 0; i--) {
    if (par[v][i] != par[u][i]) {
      v = par[v][i];
      u = par[u][i];
    }
  }
  return v == u ? v : par[v][0];
}
void dfs(long long v, long long p = -1) {
  for (auto u : tree[v]) {
    if (u != p) {
      dfs(u, v);
      sz[v] += sz[u];
    }
  }
  sz[v]++;
  if (v != st) {
    ans = max(ans, sz[v]);
  }
}
int main() {
  cin >> n >> m >> st;
  for (long long i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    graph[u - 1].push_back({v - 1, w});
    graph[v - 1].push_back({u - 1, w});
  }
  st--;
  for (long long i = 0; i < n; i++) {
    if (i != st) {
      vec.push_back(i);
    }
  }
  djikstra(st);
  sort(vec.begin(), vec.end(), cmp);
  par[st][0] = st;
  for (long long i = 1; i < lg; i++) {
    par[st][i] = par[par[st][i - 1]][i - 1];
  }
  for (auto v : vec) {
    long long p = -1;
    if (d[v] > 1e18) {
      break;
    }
    for (auto nei : graph[v]) {
      if (d[nei.first] + nei.second == d[v]) {
        p = lca(p, nei.first);
      }
    }
    h[v] = h[p] + 1;
    tree[p].push_back(v);
    par[v][0] = p;
    for (long long i = 1; i < lg; i++) {
      par[v][i] = par[par[v][i - 1]][i - 1];
    }
  }
  dfs(st);
  cout << ans << endl;
}
