#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
using ll = long long;
int n, m, s;
vector<pair<int, int>> v[N];
ll dis[N];
void dijkstra() {
  memset(dis, 63, sizeof(dis));
  dis[s] = 0;
  priority_queue<pair<ll, int>> pq;
  pq.push({0, s});
  while (!pq.empty()) {
    auto nd = pq.top();
    pq.pop();
    if (-nd.first != dis[nd.second]) continue;
    for (auto &i : v[nd.second])
      if (dis[i.first] > dis[nd.second] + i.second)
        dis[i.first] = dis[nd.second] + i.second,
        pq.push({-dis[i.first], i.first});
  }
}
struct Edge {
  int u, v, w;
} e[N];
vector<int> g[N];
namespace DT {
int deg[N], dp[N][20], dep[N], sz[N], fa[N];
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; i >= 0; --i)
    if (dep[dp[x][i]] >= dep[y]) x = dp[x][i];
  if (x == y) return x;
  for (int i = 19; i >= 0; --i)
    if (dp[x][i] != dp[y][i]) x = dp[x][i], y = dp[y][i];
  return dp[x][0];
}
vector<int> t[N];
void dfs(int pos) {
  sz[pos] = (dis[pos] != dis[0]);
  for (auto &i : t[pos]) dfs(i), sz[pos] += sz[i];
}
void build() {
  queue<int> q;
  memset(fa, -1, sizeof(fa));
  for (int i = 1; i <= n; i++)
    if (!deg[i]) fa[i] = 0, q.push(i);
  while (!q.empty()) {
    int nd = q.front();
    q.pop();
    dep[nd] = dep[fa[nd]] + 1;
    t[fa[nd]].push_back(nd);
    dp[nd][0] = fa[nd];
    for (int i = 1; i < 20; i++) dp[nd][i] = dp[dp[nd][i - 1]][i - 1];
    for (auto &i : g[nd]) {
      if (fa[i] == -1)
        fa[i] = nd;
      else
        fa[i] = lca(fa[i], nd);
      if (!--deg[i]) q.push(i);
    }
  }
}
}  // namespace DT
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m >> s;
  int t1, t2, t3;
  for (int i = 1; i <= m; i++) {
    cin >> t1 >> t2 >> t3;
    v[t1].push_back({t2, t3});
    v[t2].push_back({t1, t3});
    e[i] = {t1, t2, t3};
  }
  dijkstra();
  for (int i = 1; i <= m; i++) {
    if (dis[e[i].v] == dis[e[i].u] + e[i].w)
      g[e[i].u].push_back(e[i].v), ++DT::deg[e[i].v];
    if (dis[e[i].u] == dis[e[i].v] + e[i].w)
      g[e[i].v].push_back(e[i].u), ++DT::deg[e[i].u];
  }
  DT::build();
  DT::dfs(0);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (i != s) ans = max(ans, DT::sz[i]);
  cout << ans << endl;
  return 0;
}
