#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 4e5 + 5;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1E-8;
const double PI = acos(-1.0);
int n, m, s, l[maxn], r[maxn], c[maxn];
int fa[maxn], ind[maxn], dep[maxn], size[maxn], up[maxn][20];
vector<vector<pair<long long, long long> > > G(maxn);
vector<vector<int> > T(maxn), ZT(maxn);
long long dis[maxn];
void dij() {
  for (int i = 1; i <= n; ++i) {
    dis[i] = inf;
  }
  dis[s] = 0;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      que;
  que.push(make_pair(0, s));
  while (que.size()) {
    pair<long long, long long> u = que.top();
    que.pop();
    if (u.first > dis[u.second]) continue;
    int len = G[u.second].size();
    for (int i = 0; i < len; ++i) {
      int v = G[u.second][i].first, w = G[u.second][i].second;
      if (dis[u.second] + w >= dis[v]) continue;
      dis[v] = dis[u.second] + w;
      que.push(make_pair(dis[v], v));
    }
  }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 19; i >= 0; --i) {
    if (dep[up[u][i]] >= dep[v]) u = up[u][i];
  }
  if (u == v) return u;
  for (int i = 19; i >= 0; --i) {
    if (up[u][i] != up[v][i]) {
      u = up[u][i];
      v = up[v][i];
    }
  }
  return up[u][0];
}
void dfs(int u) {
  size[u] = dis[u] != inf;
  int len = ZT[u].size();
  for (int i = 0; i < len; ++i) {
    int v = ZT[u][i];
    dfs(v);
    size[u] += size[v];
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    G[u].push_back(make_pair(v, w));
    G[v].push_back(make_pair(u, w));
    l[i] = u, r[i] = v, c[i] = w;
  }
  dij();
  for (int i = 1; i <= m; ++i) {
    if (dis[l[i]] + c[i] == dis[r[i]]) {
      ind[r[i]]++;
      T[l[i]].push_back(r[i]);
    }
    if (dis[r[i]] + c[i] == dis[l[i]]) {
      ind[l[i]]++;
      T[r[i]].push_back(l[i]);
    }
  }
  queue<int> que;
  memset(fa, -1, sizeof fa);
  for (int i = 1; i <= n; ++i) {
    if (ind[i]) continue;
    fa[i] = 0, que.push(i);
  }
  while (que.size()) {
    int u = que.front();
    que.pop();
    dep[u] = dep[fa[u]] + 1;
    ZT[fa[u]].push_back(u);
    up[u][0] = fa[u];
    for (int i = 1; i <= 19; ++i) {
      up[u][i] = up[up[u][i - 1]][i - 1];
    }
    int len = T[u].size();
    for (int i = 0; i < len; ++i) {
      int v = T[u][i];
      if (fa[v] == -1)
        fa[v] = u;
      else
        fa[v] = lca(u, fa[v]);
      if (--ind[v] == 0) que.push(v);
    }
  }
  dfs(0);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i == s) continue;
    ans = max(ans, size[i]);
  }
  cout << ans << endl;
  return 0;
}
