#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, w;
  Edge(int a, int b) { to = a, w = b; }
};
vector<Edge> G[200010];
vector<int> DAG[200010];
vector<int> rDAG[200010];
vector<int> tree[200010];
long long dis[200010];
bool inqueue[200010];
int deg[200010];
int dep[200010];
int fa[200010][20];
int siz[200010];
void spfa(int s, int n) {
  fill(dis + 1, dis + 1 + n, 1LL << 50);
  dis[s] = 0;
  queue<int> q;
  q.push(s);
  inqueue[s] = true;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (auto e : G[cur]) {
      if (dis[cur] + e.w < dis[e.to]) {
        dis[e.to] = dis[cur] + e.w;
        if (!inqueue[e.to]) {
          inqueue[e.to] = true;
          q.push(e.to);
        }
      }
    }
    inqueue[cur] = false;
  }
}
void buildDAG(int n) {
  for (int i = 1; i <= n; i++)
    for (auto e : G[i])
      if (dis[i] + e.w == dis[e.to]) {
        DAG[i].push_back(e.to);
        rDAG[e.to].push_back(i);
        deg[e.to]++;
      }
}
int getlca(int a, int b) {
  if (dep[a] > dep[b]) swap(a, b);
  for (int i = 19; i >= 0; i--)
    if (dep[a] < dep[b] && dep[fa[b][i]] >= dep[a]) b = fa[b][i];
  for (int i = 19; i >= 0; i--)
    if (fa[a][i] != fa[b][i]) a = fa[a][i], b = fa[b][i];
  if (a == b) return a;
  return fa[a][0];
}
void update(int cur, int f) {
  dep[cur] = dep[f] + 1;
  fa[cur][0] = f;
  for (int i = 1; i <= 19; i++) {
    fa[cur][i] = fa[fa[cur][i - 1]][i - 1];
    if (!fa[cur][i]) break;
  }
}
void buildTree(int s, int n) {
  dep[0] = -1;
  queue<int> q;
  q.push(s);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    int lca = 0;
    if (!rDAG[cur].empty()) {
      lca = rDAG[cur][0];
      for (int i = 1; i < rDAG[cur].size(); i++)
        lca = getlca(lca, rDAG[cur][i]);
    }
    update(cur, lca);
    tree[lca].push_back(cur);
    for (auto o : DAG[cur])
      if (--deg[o] == 0) q.push(o);
  }
}
void dfs(int cur) {
  siz[cur] = 1;
  for (auto o : tree[cur]) {
    dfs(o);
    siz[cur] += siz[o];
  }
}
int main() {
  int n, m, s, u, v, w;
  scanf("%d%d%d", &n, &m, &s);
  for (int i = 0; i != m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    G[u].emplace_back(v, w);
    G[v].emplace_back(u, w);
  }
  spfa(s, n);
  buildDAG(n);
  buildTree(s, n);
  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;
}
