#include <bits/stdc++.h>
using namespace std;
const int N = 200050, M = 20;
const long long INF = 1000000000000000ll;
const long long P = 1e9 + 7;
template <typename T>
inline void read(T& first, char s = getchar()) {
  first = 0;
  while (s > '9' || s < '0') s = getchar();
  while (s <= '9' && s >= '0') first = first * 10 + s - '0', s = getchar();
}
struct Edge {
  int to, v;
  Edge() {}
  Edge(int _to, int _v) : to(_to), v(_v) {}
};
struct Node {
  int first;
  long long v;
  Node() {}
  Node(int _x, long long _v) : first(_x), v(_v) {}
  const bool operator<(const Node& b) const { return b.v < v; }
};
vector<Edge> g[N];
priority_queue<Node> q;
stack<int> stk;
vector<int> h[N];
vector<int> g2[N];
int ans;
int n, m, str;
long long d[N];
int r[N];
int fa[N];
int dep[N];
int f[N][20];
int siz[N];
bool vis[N];
inline void pre(int first) {
  f[first][0] = fa[first];
  dep[first] = dep[fa[first]] + 1;
  for (int i = 1; i < M; i++) f[first][i] = f[f[first][i - 1]][i - 1];
}
inline int lca(int a, int b) {
  if (dep[a] < dep[b]) swap(a, b);
  int t = dep[a] - dep[b];
  for (int i = 0; i < M; i++)
    if (t & (1 << i)) a = f[a][i];
  if (a == b) return a;
  for (int i = M - 1; i >= 0; i--) {
    if (f[a][i] != f[b][i]) a = f[a][i], b = f[b][i];
  }
  return f[a][0];
}
inline int dfs(int first, int fa) {
  siz[first] = 1;
  for (int i : g2[first]) {
    if (i != fa) siz[first] += dfs(i, first);
  }
  if (first != str) ans = max(ans, siz[first]);
  return siz[first];
}
int main() {
  int u, v, w;
  read(n), read(m), read(str);
  for (int i = 1; i <= n; i++) d[i] = INF;
  for (int i = 1; i <= m; i++) {
    read(u), read(v), read(w);
    g[u].push_back(Edge(v, w));
    g[v].push_back(Edge(u, w));
  }
  d[str] = 0;
  q.push(Node(str, 0));
  while (!q.empty()) {
    int first = q.top().first;
    q.pop();
    if (vis[first]) continue;
    vis[first] = 1;
    for (Edge e : g[first]) {
      int t = e.to, v = e.v;
      if (d[t] > d[first] + v) {
        d[t] = d[first] + v;
        q.push(Node(t, d[t]));
      }
    }
  }
  for (int first = 1; first <= n; first++) {
    for (Edge e : g[first]) {
      int t = e.to, v = e.v;
      if (d[t] == d[first] + v) {
        r[t]++;
        h[first].push_back(t);
      }
    }
  }
  fa[str] = str;
  pre(str);
  stk.push(str);
  while (!stk.empty()) {
    int first = stk.top();
    stk.pop();
    for (int i : h[first]) {
      r[i]--;
      if (fa[i] == 0)
        fa[i] = first;
      else
        fa[i] = lca(fa[i], first);
      if (r[i] == 0) {
        stk.push(i);
        pre(i);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    g2[fa[i]].push_back(i);
  }
  dfs(str, str);
  cout << ans << endl;
  return 0;
}
