#include <bits/stdc++.h>
using namespace std;
int read() {
  int s = 0, t = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') t = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return s * t;
}
struct edge {
  int to, lt, v;
} e[600010];
int in[600010], cnt;
void add(int x, int y, int v) {
  e[++cnt].to = y;
  e[cnt].lt = in[x];
  in[x] = cnt;
  e[cnt].v = v;
  e[++cnt].to = x;
  e[cnt].lt = in[y];
  in[y] = cnt;
  e[cnt].v = v;
}
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    q;
long long dis[600010];
bool vis[600010];
vector<int> E[600010];
int f[600010][20], d[600010], n, m, s;
void Add(int x, int y) {
  E[x].push_back(y);
  d[y]++;
}
void dijkstra() {
  memset(dis, 48, sizeof(dis));
  dis[s] = 0;
  q.push(make_pair(0, s));
  while (!q.empty()) {
    int x = q.top().second;
    q.pop();
    if (vis[x]) continue;
    vis[x] = 1;
    for (int i = in[x]; i; i = e[i].lt) {
      int y = e[i].to;
      if (dis[y] > dis[x] + e[i].v)
        dis[y] = dis[x] + e[i].v, q.push(make_pair(dis[y], y));
    }
  }
  for (int x = 1; x <= n; x++)
    for (int i = in[x]; i; i = e[i].lt) {
      int y = e[i].to;
      if (dis[y] == dis[x] + e[i].v) Add(x, y);
    }
}
queue<int> w;
int dep[600010];
vector<int> t[600010];
void Tadd(int x, int y) { t[x].push_back(y); }
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int v = dep[x] - dep[y];
  for (int i = 0; i < 20; i++)
    if (v >> i & 1) x = f[x][i];
  if (x == y) return x;
  for (int i = 19; ~i; i--)
    if (f[x][i] ^ f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
void build() {
  for (int i = 1; i <= n; i++)
    if (!d[i])
      f[i][0] = 0, w.push(i);
    else
      f[i][0] = -1;
  while (!w.empty()) {
    int x = w.front();
    w.pop();
    dep[x] = dep[f[x][0]] + 1;
    Tadd(f[x][0], x);
    for (int i = 1; i < 20; i++) f[x][i] = f[f[x][i - 1]][i - 1];
    for (int i = 0; i < E[x].size(); i++) {
      int y = E[x][i];
      --d[y];
      if (f[y][0] == -1)
        f[y][0] = x;
      else
        f[y][0] = LCA(f[y][0], x);
      if (!d[y]) w.push(y);
    }
  }
}
int sz[600010];
void dfs(int x) {
  sz[x] = dis[x] != dis[0];
  for (int i = 0; i < t[x].size(); i++) {
    int y = t[x][i];
    dfs(y);
    sz[x] += sz[y];
  }
}
int main() {
  n = read(), m = read(), s = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read(), v = read();
    add(x, y, v);
  }
  dijkstra();
  build();
  dfs(0);
  int ans = 0;
  for (int i = 1; i <= n; i++)
    if (i != s) ans = max(ans, sz[i]);
  printf("%d\n", ans);
  return 0;
}
