#include <bits/stdc++.h>
using namespace std;
template <class T>
void rd(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  x *= f;
}
const int maxn = 3e5 + 5;
int n, m, s, ans;
int u[maxn], v[maxn], w[maxn];
int du[maxn], dep[maxn], pre[maxn][21], siz[maxn];
bool vis[maxn];
long long dis[maxn];
vector<int> sta, to[maxn], son[maxn];
struct Edge {
  int v, w, nxt;
};
int head[maxn];
vector<Edge> e;
void adde(int u, int v, int w) {
  e.push_back((Edge){v, w, head[u]});
  head[u] = e.size() - 1;
}
void dijkstra(int s) {
  memset(vis, 0, sizeof(vis));
  memset(dis, 0x3f, sizeof(dis));
  dis[s] = 0;
  priority_queue<pair<long long, int> > q;
  q.push(pair<long long, int>(0, s));
  while (!q.empty()) {
    int u = q.top().second;
    q.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (int i = head[u]; ~i; i = e[i].nxt) {
      int v = e[i].v;
      if (dis[v] > dis[u] + e[i].w) {
        dis[v] = dis[u] + e[i].w;
        q.push(pair<long long, int>(-dis[v], v));
      }
    }
  }
}
void topo() {
  queue<int> q;
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    sta.push_back(u);
    for (int i = head[u]; ~i; i = e[i].nxt) {
      int v = e[i].v;
      if (--du[v] == 0) q.push(v);
    }
  }
}
int lca(int a, int b) {
  if (dep[a] > dep[b]) swap(a, b);
  for (int i = (20); i >= (0); --i)
    if (dep[a] <= dep[b] - (1 << i)) b = pre[b][i];
  if (a == b) return a;
  for (int i = (20); i >= (0); --i)
    if (pre[a][i] != pre[b][i]) a = pre[a][i], b = pre[b][i];
  return pre[a][0];
}
void update(int u, int v, int w) {
  if (dis[v] == dis[u] + w) {
    adde(u, v, w), du[v]++;
    to[v].push_back(u);
  }
}
void build() {
  dijkstra(s);
  memset(head, -1, sizeof(head));
  e.clear();
  for (int i = (1); i <= (m); ++i) {
    update(u[i], v[i], w[i]);
    update(v[i], u[i], w[i]);
  }
  topo();
  dep[s] = 1;
  for (int i = (1); i <= ((int)sta.size() - 1); ++i) {
    int u = sta[i];
    int f = to[u][0];
    for (int j = (1); j <= ((int)to[u].size() - 1); ++j) f = lca(f, to[u][j]);
    dep[u] = dep[f] + 1;
    pre[u][0] = f;
    for (int j = (1); j <= (20); ++j) pre[u][j] = pre[pre[u][j - 1]][j - 1];
    son[f].push_back(u);
  }
}
void dfs(int u) {
  siz[u] = 1;
  for (int i = (0); i <= ((int)son[u].size() - 1); ++i) {
    int v = son[u][i];
    dfs(v);
    ans = max(ans, siz[v]);
    siz[u] += siz[v];
  }
}
void sol() {
  build();
  dfs(s);
  printf("%d\n", ans);
}
int main() {
  memset(head, -1, sizeof(head));
  rd(n), rd(m), rd(s);
  for (int i = (1); i <= (m); ++i) {
    rd(u[i]), rd(v[i]), rd(w[i]);
    adde(u[i], v[i], w[i]);
    adde(v[i], u[i], w[i]);
  }
  sol();
  return 0;
}
