#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e15 + 10;
const int maxn = 2e5 + 10;
const int mx = 20;
vector<pair<long long, long long>> e[maxn];
vector<int> g[maxn], rg[maxn], h[maxn], tmp;
int n, m, s;
long long dis[maxn];
int f[maxn][mx + 2], dep[maxn], ru[maxn], ans[maxn];
void dijkstra(int s) {
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      q;
  fill(dis, dis + n + 1, inf);
  dis[s] = 0;
  q.push(pair<long long, long long>(dis[s], s));
  while (!q.empty()) {
    pair<long long, long long> now = q.top();
    int u = now.second;
    q.pop();
    if (dis[u] < now.first) continue;
    for (int i = 0; i < e[u].size(); i++) {
      int v = e[u][i].first;
      long long w = e[u][i].second;
      if (dis[v] > dis[u] + w) {
        dis[v] = dis[u] + w;
        q.push(pair<long long, long long>(dis[v], v));
      }
    }
  }
}
void tpsort() {
  queue<int> q;
  q.push(0);
  for (int i = 1; i <= n; i++) {
    if (!ru[i] && dis[i] != inf) {
      g[0].push_back(i);
      rg[i].push_back(0);
      ru[i]++;
    }
  }
  while (!q.empty()) {
    int top = q.front();
    q.pop();
    tmp.push_back(top);
    for (int i = 0; i < g[top].size(); i++) {
      int v = g[top][i];
      ru[v]--;
      if (!ru[v]) q.push(v);
    }
  }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = mx; i >= 0; i--)
    if (dep[f[u][i]] >= dep[v]) u = f[u][i];
  if (u == v) return u;
  for (int i = mx; i >= 0; i--)
    if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
  return f[u][0];
}
void dfs(int u, int fa) {
  ans[u] = 1;
  for (int i = 0; i < h[u].size(); i++) {
    int v = h[u][i];
    if (v == fa) continue;
    dfs(v, u);
    ans[u] += ans[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);
    e[u].push_back(pair<long long, long long>(v, w));
    e[v].push_back(pair<long long, long long>(u, w));
  }
  dijkstra(s);
  for (int i = 1; i <= n; i++) {
    if (dis[i] == inf) continue;
    for (auto it : e[i]) {
      if (dis[i] + it.second == dis[it.first]) {
        g[i].push_back(it.first);
        ru[it.first]++;
        rg[it.first].push_back(i);
      }
    }
  }
  tpsort();
  for (int i = 1; i < tmp.size(); i++) {
    int p = tmp[i], y = rg[p][0];
    for (int j = 1; j < rg[p].size(); j++) y = lca(y, rg[p][j]);
    h[y].push_back(p);
    dep[p] = dep[y] + 1;
    f[p][0] = y;
    for (int i = 1; i <= mx; i++) f[p][i] = f[f[p][i - 1]][i - 1];
  }
  dfs(s, -1);
  int res = 0;
  for (int i = 1; i <= n; i++) {
    if (i == s) continue;
    res = max(res, ans[i]);
  }
  printf("%d\n", res);
  return 0;
}
