#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
const int M = 300005;
struct Edge {
  int next, to, w;
} edge[M << 1];
int head[N], cnt, n, m, q[N * 20], S;
void save(int a, int b, int c = 0) {
  edge[cnt] = (Edge){head[a], b, c}, head[a] = cnt++;
}
int dep[N], fa[N][22];
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; ~i; --i)
    if (dep[fa[x][i]] >= dep[y]) {
      x = fa[x][i];
    }
  if (x == y) return x;
  for (int i = 19; ~i; --i)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
bool inq[N];
long long dis[N];
vector<pair<int, int> > vec[N];
vector<int> rev[N];
void spfa() {
  int h, t;
  q[h = t = 0] = S;
  memset(dis, 63, sizeof(dis));
  dis[S] = 0;
  inq[S] = 1;
  while (h <= t) {
    int x = q[h++];
    for (pair<int, int> a : vec[x]) {
      int d = a.second, y = a.first;
      if (dis[y] > dis[x] + d) {
        dis[y] = dis[x] + d;
        if (!inq[y]) q[++t] = y;
      }
    }
    inq[x] = 0;
  }
}
int deg[N];
namespace Graph {
int head[N], cnt, cur[N];
struct Edge {
  int next, to;
} edge[N << 1];
void save(int a, int b) { edge[cnt] = (Edge){head[a], b}, head[a] = cnt++; }
void dfs(int x) {
  cur[x] = 1;
  for (int i = head[x]; ~i; i = edge[i].next) {
    dfs(edge[i].to);
    cur[x] += cur[edge[i].to];
  }
}
}  // namespace Graph
void toposort() {
  int h = 0, t = 0;
  q[0] = S;
  dep[S] = 2;
  while (h <= t) {
    int x = q[h++];
    if (x != S) {
      int lca = *rev[x].begin();
      for (int y : rev[x]) lca = LCA(y, lca);
      dep[x] = dep[lca] + 1;
      fa[x][0] = lca;
      for (int i = 1; i <= 19; ++i) fa[x][i] = fa[fa[x][i - 1]][i - 1];
      Graph ::save(lca, x);
    }
    for (int i = head[x]; ~i; i = edge[i].next)
      if ((--deg[edge[i].to]) == 0) q[++t] = edge[i].to;
  }
}
int main() {
  memset(head, -1, sizeof(head));
  memset(Graph ::head, -1, sizeof(Graph ::head));
  scanf("%d%d%d", &n, &m, &S);
  for (int i = 1; i <= m; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    vec[a].push_back(make_pair(b, c));
    vec[b].push_back(make_pair(a, c));
  }
  spfa();
  dep[0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (pair<int, int> c : vec[i])
      if (dis[c.first] == dis[i] + c.second)
        deg[c.first]++, save(i, c.first, 0), rev[c.first].push_back(i);
  }
  toposort();
  Graph ::dfs(S);
  int mx = 0;
  for (int i = 1; i <= n; ++i)
    if (i != S) mx = max(mx, Graph ::cur[i]);
  printf("%d\n", mx);
  return 0;
}
