#include <bits/stdc++.h>
using namespace std;
long long dis[200005];
bool vis[200005];
int x[300005], y[300005], z[300005], target[600005], pre[600005], last[200005],
    tot, w[600005], d[200005], f[200005][18], deep[200005], siz[200005],
    g[200005];
vector<int> to[200005], to2[200005];
priority_queue<pair<long long, int>, vector<pair<long long, int>>,
               greater<pair<long long, int>>>
    q;
queue<int> q2;
void add(int x, int y, int z) {
  target[++tot] = y;
  pre[tot] = last[x];
  last[x] = tot;
  w[tot] = z;
}
int lca(int x, int y) {
  if (deep[x] < deep[y]) swap(x, y);
  for (int i = 17; i >= 0; i--)
    if (deep[f[x][i]] >= deep[y]) x = f[x][i];
  if (x == y) return x;
  for (int i = 17; i >= 0; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
void dfs(int x) {
  siz[x] = 1;
  for (auto tar : to2[x]) dfs(tar), siz[x] += siz[tar];
}
int main() {
  int n, m, s;
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 1; i <= m; i++)
    scanf("%d%d%d", &x[i], &y[i], &z[i]), add(x[i], y[i], z[i]),
        add(y[i], x[i], z[i]);
  q.push({0, s});
  for (int i = 1; i <= n; i++) dis[i] = 1e16;
  dis[s] = 0;
  while (q.size()) {
    int now = q.top().second;
    q.pop();
    if (vis[now]) continue;
    vis[now] = 1;
    for (int i = last[now]; i; i = pre[i]) {
      int tar = target[i];
      if (dis[tar] > dis[now] + w[i])
        dis[tar] = dis[now] + w[i], q.push({dis[tar], tar});
    }
  }
  for (int i = 1; i <= m; i++)
    if (dis[y[i]] == dis[x[i]] + z[i])
      to[x[i]].push_back(y[i]), d[y[i]]++;
    else if (dis[x[i]] == dis[y[i]] + z[i])
      to[y[i]].push_back(x[i]), d[x[i]]++;
  q2.push(s);
  while (q2.size()) {
    int now = q2.front();
    q2.pop();
    f[now][0] = g[now];
    deep[now] = deep[g[now]] + 1;
    to2[g[now]].push_back(now);
    for (int i = 1; i <= 17; i++) f[now][i] = f[f[now][i - 1]][i - 1];
    for (auto tar : to[now]) {
      d[tar]--;
      if (!g[tar])
        g[tar] = now;
      else
        g[tar] = lca(g[tar], now);
      if (!d[tar]) q2.push(tar);
    }
  }
  dfs(s);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (i != s) ans = max(ans, siz[i]);
  printf("%d", ans);
  return 0;
}
