#include <bits/stdc++.h>
using namespace std;
const int N = 600005;
const long long inf = 1e18;
vector<int> pre[N];
long long dis[N];
int head[N], nxt[N], to[N], e;
int w[N];
int n, m;
priority_queue<pair<long long, int> > pq;
inline void init() {
  memset(head, -1, sizeof(head));
  e = 0;
}
inline void add_edge(int x, int y, int z) {
  to[e] = y;
  nxt[e] = head[x];
  w[e] = z;
  head[x] = e++;
}
void dijkstra(int s) {
  for (int i = (1); i <= (n); i++) dis[i] = inf;
  dis[s] = 0;
  pq.push(make_pair(0, s));
  while (!pq.empty()) {
    int x = pq.top().second;
    pq.pop();
    for (int i = head[x]; i + 1; i = nxt[i]) {
      if (dis[x] + w[i] < dis[to[i]]) {
        dis[to[i]] = dis[x] + w[i];
        pre[to[i]].clear();
        pq.push(make_pair(-dis[to[i]], to[i]));
      }
      if (dis[x] + w[i] == dis[to[i]]) pre[to[i]].push_back(x);
    }
  }
}
vector<int> q;
namespace Graph {
int head[N], nxt[N], to[N], e, de[N];
inline void init() {
  memset(head, -1, sizeof(head));
  e = 0;
}
inline void add_edge(int x, int y) {
  to[e] = y;
  nxt[e] = head[x];
  de[y]++;
  head[x] = e++;
}
inline void Build(int s) {
  init();
  for (int i = (1); i <= (n); i++)
    for (int j = 0; j < pre[i].size(); j++) add_edge(pre[i][j], i);
  q.push_back(s);
  for (int i = 0; i < n && i < q.size(); i++) {
    int x = q[i];
    for (int j = head[x]; j + 1; j = nxt[j]) {
      de[to[j]]--;
      if (!de[to[j]]) q.push_back(to[j]);
    }
  }
  n = q.size();
}
};  // namespace Graph
int dep[N], sz[N];
int fa[200005][20];
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int dif = dep[x] - dep[y];
  for (int i = (0); i <= (18); i++)
    if ((1 << i) & dif) x = fa[x][i];
  for (int i = (18); i >= (0); i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return x == y ? x : fa[x][0];
}
int main() {
  int s;
  scanf("%d%d%d", &n, &m, &s);
  init();
  for (int i = (1); i <= (m); i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    add_edge(x, y, z);
    add_edge(y, x, z);
  }
  dijkstra(s);
  Graph::Build(s);
  dep[s] = 1;
  for (int i = (0); i <= (18); i++) fa[s][i] = s;
  for (int i = (1); i <= (n - 1); i++) {
    int x = q[i];
    int l = pre[x][0];
    for (int j = 1; j < pre[x].size(); j++) l = lca(l, pre[x][j]);
    fa[x][0] = l;
    dep[x] = dep[l] + 1;
    for (int j = (1); j <= (18); j++) fa[x][j] = fa[fa[x][j - 1]][j - 1];
  }
  for (int i = (n - 1); i >= (1); i--) {
    int x = q[i];
    sz[x]++;
    sz[fa[x][0]] += sz[x];
  }
  int ans = 0;
  for (int i = (1); i <= (n - 1); i++) ans = max(ans, sz[q[i]]);
  printf("%d\n", ans);
  return 0;
}
